我有 2 个使用 docker-compose 运行的不同容器。这是我的 docker-compose.yml:
version: '3'
services:
#Create backend container
backend:
build: ./backend # path to Dockerfile
ports: # Port binding to host from docker container
- "5000:5000"
container_name: buzzworks-backend
volumes:
- ${PWD}/backend:/app
depends_on:
- db
environment:
FLASK_APP: flaskr
FLASK_ENV: development
NEO_USER: ${NEO_USER}
NEO_PW: ${NEO_PW}
db:
image: neo4j:4.1.1
container_name: buzzworks-neo4j
ports:
- "7474:7474"
- "7687:7687"
volumes:
- ${HOME}/neo4j/data:/data
- ${HOME}/neo4j/logs:/logs
- ${HOME}/neo4j/import:/var/lib/neo4j/import
- ${HOME}/neo4j/plugins:/plugins
environment:
NEO4J_AUTH: ${NEO_USER}/${NEO_PW}
NEO4J_dbms_logs_debug_level: ${NEO_DEBUG_LEVEL}
它生成的相应网络在我看来是正确的:
{
"Name": "buzzworksai_default",
"Id": "db4efc0286a9464cadde13cf1306f241b7a353295904b15b163e761289ba9d3f",
"Created": "2020-08-27T11:23:15.925483629-04:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"640650c163f746e480bf677abdeaf8edf6483b7dac2a260c2e3b3bc3319dffef": {
"Name": "buzzworks-neo4j",
"EndpointID": "ddbad1a179cc51655a779b07c91d6d949b0612bf985abc9c45e1794b35f4a565",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
},
"ba47173d1dbc31e4e416eaf30d2314e6d2a20a36b389cb76cd1edcbea489184e": {
"Name": "buzzworks-backend",
"EndpointID": "17ff278f3db5ad609be682cdf912ca755587e07ef08d6023bf3ecb33a6c4bc31",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "default",
"com.docker.compose.project": "buzzworksai",
"com.docker.compose.version": "1.26.2"
}
}
]
我可以很好地访问neo4j数据库的Web界面。当我尝试使用neomodel
. 我尝试neomodel_remove_labels --db bolt://<user>:<password>@db:7687
从 python 容器的 shell 使用适当的凭据运行。我收到此错误:
Traceback (most recent call last):
File "/usr/local/bin/neomodel_remove_labels", line 35, in <module>
main()
File "/usr/local/bin/neomodel_remove_labels", line 30, in main
db.set_connection(bolt_url)
File "/usr/local/lib/python3.8/dist-packages/neomodel/util.py", line 93, in set_connection
self.driver = GraphDatabase.driver(u.scheme + '://' + hostname,
File "/usr/local/lib/python3.8/dist-packages/neo4j/__init__.py", line 108, in driver
return Driver(uri, **config)
File "/usr/local/lib/python3.8/dist-packages/neo4j/__init__.py", line 147, in __new__
return subclass(uri, **config)
File "/usr/local/lib/python3.8/dist-packages/neo4j/__init__.py", line 221, in __new__
pool.release(pool.acquire())
File "/usr/local/lib/python3.8/dist-packages/neobolt/direct.py", line 715, in acquire
return self.acquire_direct(self.address)
File "/usr/local/lib/python3.8/dist-packages/neobolt/direct.py", line 608, in acquire_direct
connection = self.connector(address, error_handler=self.connection_error_handler)
File "/usr/local/lib/python3.8/dist-packages/neo4j/__init__.py", line 218, in connector
return connect(address, **dict(config, **kwargs))
File "/usr/local/lib/python3.8/dist-packages/neobolt/direct.py", line 972, in connect
raise last_error
File "/usr/local/lib/python3.8/dist-packages/neobolt/direct.py", line 963, in connect
s, der_encoded_server_certificate = _secure(s, host, security_plan.ssl_context, **config)
File "/usr/local/lib/python3.8/dist-packages/neobolt/direct.py", line 854, in _secure
s = ssl_context.wrap_socket(s, server_hostname=host if HAS_SNI and host else None)
File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/usr/lib/python3.8/ssl.py", line 1040, in _create
self.do_handshake()
File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error
我试图从我的主机访问容器,bolt://<user>:<password>@localhost:7687
但我仍然得到同样的错误。