Strange neo4j-shell issue connecting to Neo4j in a docker instance

微笑、不失礼 提交于 2020-01-06 13:07:13

问题


I have a really strange problem connecting to a Neo4j instance running in a docker instance. But first things first, here is my set up:

Everything runs on a MacOS. I use boot2docker, so the actual Docker instances run in a VirtualBox. I am able to reproduce this issue with Neo4j 2.1.5 and with Neo4j 2.2.0-M04. Additionally, I installed Neo4j locally via homebrew and it is version 2.1.7. It is installed to have a neo4j-shell available. The docker instances are accessible from the outside via 192.168.59.104. The docker instance itself has a 172.17.0.x IP address.

The problem: I try to connect with neo4j-shell like this: neo4j-shell -v -host 192.168.59.104 -port 1337 -name shell. After a couple of minutes, it fails with:

ERROR (-v for expanded information):
    Connection refused
java.rmi.ConnectException: Connection refused to host: 172.17.0.2; nested exception is:
    java.net.ConnectException: Operation timed out
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
    at com.sun.proxy.$Proxy1.welcome(Unknown Source)
    at org.neo4j.shell.impl.AbstractClient.sayHi(AbstractClient.java:215)
    at org.neo4j.shell.impl.RemoteClient.findRemoteServer(RemoteClient.java:63)
    at org.neo4j.shell.impl.RemoteClient.<init>(RemoteClient.java:55)
    at org.neo4j.shell.impl.RemoteClient.<init>(RemoteClient.java:43)
    at org.neo4j.shell.ShellLobby.newClient(ShellLobby.java:165)
    at org.neo4j.shell.StartClient.startRemote(StartClient.java:297)
    at org.neo4j.shell.StartClient.start(StartClient.java:175)
    at org.neo4j.shell.StartClient.main(StartClient.java:120)
Caused by: java.net.ConnectException: Operation timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at java.net.Socket.connect(Socket.java:538)
    at java.net.Socket.<init>(Socket.java:434)
    at java.net.Socket.<init>(Socket.java:211)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
    ... 14 more

The interesting part is, that it fails by trying to connect 172.17.0.2 instead of the provided IP address.

What I did so far:

  • Double check neo4j.properties are correct
    • remote_shell_host=0.0.0.0 is set
    • remote_shell_port=1337 is set
  • check the ports are exposed properly with docker ps:
    CONTAINER ID        IMAGE                  COMMAND                CREATED             STATUS              PORTS                                            NAMES
    099cfd1b8018        daneroo/neo4j:latest   "/bin/bash -c /launc   3 minutes ago       Up 3 minutes        0.0.0.0:1337->1337/tcp, 0.0.0.0:7474->7474/tcp   neo4j
    
  • Some Google and SO searches, but without any success.
  • Different neo4j versions and docker images
  • Basic connection checks with telnet 192.168.59.104 1337. This is successful.
  • Catch up with Mark Needham at todays neo4j meetup

So, do I miss something? In theory this should happen every time you can access the Neo4j through another IP address than the Neo4j instance can see (e.g. if you run a Neo4j instance at home on a machine with the IP 192.168.x.y and you try to access it via your public IP you have at this time). Where is the client, running outside the Neo4j environment, getting the internal IP address from? Is there a way to work around this issue?


回答1:


I think it might be related to the RMI protocol that the shell uses to communicate with Neo4j. Afaik RMI also uses some additional ports and it might redirect the initial request. there is a system property in Java that you might want to try to set in neo4j-wrapper.conf: -Djava.rmi.server.hostname=192.168.59.104

see:

  • http://courses.cs.washington.edu/courses/cse341/98au/java/jdk1.2beta4/docs/guide/rmi/rmiNetworkingFAQ.html
  • http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/javarmiproperties.html


来源:https://stackoverflow.com/questions/28974592/strange-neo4j-shell-issue-connecting-to-neo4j-in-a-docker-instance

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!