Search code examples
neo4jdockerjupyter-notebookpy2neo

Connecting docker instance with python notebook to docker instance with Neo4J


I am running a Jupyter notebook docker instance (https://github.com/jupyter/docker-stacks/tree/master/all-spark-notebook) and I've installed py2neo on it.

I am also running a docker container with Neo4J installed with port 7474 exposed.

The problem is I cannot seem to connect to the REST interface of the Neo4J docker from the notebook docker. I think the problem is related to the definition of localhost.

What worked so far. I used only the Neo4J docker and start a local notebook (ipython notebook) then the following works:

import py2neo

from py2neo import Node, Relationship, Graph, authenticate

authenticate("http://localhost:7474", "neo4j", "admin")

graph = Graph('http://localhost:7474/db/data') 

graph.cypher.execute('match (y:Year) return y')

The same code doesn't work in the notebook which is running in a separate docker container since the definition of localhost is not the same. But now I don't understand what it should be:

I've used docker inspect on the Neo4J container and used the following two in an attempt to find the address corresponding to my localhost:

  • "Gateway": "xxx.yy.42.1"
  • "IPAddress": "xxx.yy.0.3"

But both of them result in ClientError: 401 Unauthorized

Any suggestion on how to overcome this issue? (Note that my current docker version is 1.7.1, thus not support network yet, but I could obviously upgrade if that's necessary.)


Solution

  • graph = Graph('https://' + username + ':' + pwd + '@' + ip_neo + ':7473 /db/data')
    

    This seems to work. Note that you need port 7473 which is the standard HTTPS port. No success getting the approach with authenticate to work.

    For ip_neo I inspect the neo4J docker instance:

    sudo docker inspect neo4j | grep "Gateway"