我在一台主机上使用两个 docker 容器。第一个是基于带有一些转发端口(7474)的普通 neo4j:2.3 映像。第二个是基于python:2.7的容器。使用 curl 我可以从主机级别和第二台机器访问 db(使用主机本身的 IP)。问题是我编写并移植到该容器的代码将不再运行。我收到这样的错误:
Traceback (most recent call last):
File "/app/runserver.py", line 1, in <module>
from orangebox import app
File "/app/orangebox/__init__.py", line 5, in <module>
from orangebox.context import ob
File "/app/orangebox/context.py", line 2, in <module>
from orangebox.domain.factory import DomainFactory
File "/app/orangebox/domain/factory.py", line 4, in <module>
from orangebox.domain.boxes import Box
File "/app/orangebox/domain/boxes.py", line 3, in <module>
from orangebox.domain.users import User
File "/app/orangebox/domain/users.py", line 4, in <module>
class User(StructuredNode):
File "/app/src/neomodel/neomodel/core.py", line 65, in __new__
install_labels(inst)
File "/app/src/neomodel/neomodel/core.py", line 15, in install_labels
db.new_session()
File "/app/src/neomodel/neomodel/util.py", line 119, in new_session
if self.session.neo4j_version < (2, 0):
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 958, in neo4j_version
return version_tuple(self.resource.metadata["neo4j_version"])
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 213, in metadata
self.get()
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 258, in get
response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs)
File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 966, in get
return self.__get_or_head("GET", if_modified_since, headers, redirect_limit, **kwargs)
File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 943, in __get_or_head
return rq.submit(redirect_limit=redirect_limit, **kwargs)
File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 433, in submit
http, rs = submit(self.method, uri, self.body, self.headers)
File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 362, in submit
raise SocketError(code, description, host_port=uri.host_port)
py2neo.packages.httpstream.http.SocketError: Connection refused
我也尝试在端口 7473 使用 https,但它也不起作用。从调用方来看,我正在使用以下调用:
from py2neo import authenticate, Graph
from py2neo.ext.ogm import Store
import os
class DatabaseConnection(object):
def __init__(self, address):
print "Connecting to Neo4j database using URL %s" % os.environ['DB_URL']
self.graph = Graph(address)
self.store = Store(self.graph)
def get_graph(self):
return self.graph
def get_cypher(self):
return self.graph.cypher
def get_store(self):
return self.store
authenticate("172.17.0.1:7474", "neo4j", "orangebox")
db_connection = DatabaseConnection(address = "http://172.17.0.1:7474/db/data")
用户名和密码正确。当它不是我未经授权时(所以连接是可能的......)
Connecting to Neo4j database using URL http://172.17.0.1:7474/db/data/
Traceback (most recent call last):
File "/app/runserver.py", line 1, in <module>
from orangebox import app
File "/app/orangebox/__init__.py", line 5, in <module>
from orangebox.context import ob
File "/app/orangebox/context.py", line 2, in <module>
from orangebox.domain.factory import DomainFactory
File "/app/orangebox/domain/factory.py", line 3, in <module>
from orangebox.database.connection import db_connection
File "/app/orangebox/database/connection.py", line 22, in <module>
db_connection = DatabaseConnection(address = os.environ['DB_URL'])
File "/app/orangebox/database/connection.py", line 10, in __init__
self.store = Store(self.graph)
File "/usr/local/lib/python2.7/site-packages/py2neo/ext/ogm/store.py", line 42, in __init__
if self.graph.supports_optional_match:
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 1087, in supports_optional_match
return self.neo4j_version >= (2, 0)
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 958, in neo4j_version
return version_tuple(self.resource.metadata["neo4j_version"])
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 213, in metadata
self.get()
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 261, in get
raise Unauthorized(self.uri.string)
py2neo.error.Unauthorized: http://172.17.0.1:7474/db/data/
在 docker neo4j 容器上,我只看到:
root@ubuntu-14:/home/vagrant# docker run --publish=7474:7474 --volume=$HOME/neo4j/data:/data kbhit/orangebox-db
Starting Neo4j Server console-mode...
2016-05-13 14:01:35.076+0000 INFO Successfully started database
2016-05-13 14:01:35.112+0000 INFO Starting HTTP on port 7474 (2 threads available)
2016-05-13 14:01:35.327+0000 INFO Enabling HTTPS on port 7473
2016-05-13 14:01:35.417+0000 INFO Mounting static content at /webadmin
2016-05-13 14:01:35.485+0000 INFO Mounting static content at /browser
2016-05-13 14:01:36.718+0000 INFO Remote interface ready and available at http://0.0.0.0:7474/
2016-05-13 14:02:17.825+0000 WARN Failed authentication attempt for 'neo4j' from 172.17.0.1
这怎么可能?
当我使用指南https://www.digitalocean.com/community/tutorials/how-to-install-neo4j-on-an-ubuntu-vps在同一个容器中安装 neo4j-service 时,它可以工作