# Connect to Neo4j in Docker from python in a different Docker container

**URL:** <https://community.neo4j.com/t/connect-to-neo4j-in-docker-from-python-in-a-different-docker-container/17641>\
**Category:** Operations\
**Created:** [April 26, 2020, 6:24pm UTC](https://community.neo4j.com/t/connect-to-neo4j-in-docker-from-python-in-a-different-docker-container/17641 "2020-04-26T18:24:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleksandr](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/aleksandr/32/4376_2.png) [@aleksandr](https://community.neo4j.com/u/aleksandr)\
**Post date:** [April 26, 2020, 6:24pm UTC](https://community.neo4j.com/t/connect-to-neo4j-in-docker-from-python-in-a-different-docker-container/17641/1 "2020-04-26T18:24:07Z")

</div>

I am having difficulty connecting to Neo4j running in a Docker container from python in a different Docker container on Ubuntu 18.04. Here are some details:

**Creating the container**  
$ sudo docker run   
--name Neo4j.4C   
-p27474:7474   
-d   
--env=NEO4J\_AUTH=none   
--memory=6G neo4j:4.0.3

**TEST 1** : With the proper python packages (neo4j/py2neo)- I am able to connect to Neo4j successfully from the **host** machine

```auto
>>> from py2neo import Graph
>>> graph = Graph('http://127.0.0.1:27474/') 
>>> graph.run('MATCH (x) RETURN COUNT(x)').data() # <- THIS WORKS

```

**TEST 2** : However, I am not able to make a similar connection from python within a separate Docker container:

```auto
>>> from py2neo import Graph
>>> graph = Graph('http://172.17.0.1:27474/')
>>> graph.run('MATCH (x) RETURN COUNT(x)') # <- HANGS

```

Within the Neo4j container, I do not see anything under /var/lib/neo4j/logs/debug.log. the last two entries are from startup:

```auto
2020-04-26 15:19:42.179+0000 INFO [o.n.s.AbstractNeoServer$ServerComponentsLifecycleAdapter] [system] Starting web server
2020-04-26 15:19:44.809+0000 INFO [o.n.s.AbstractNeoServer$ServerComponentsLifecycleAdapter] [system] Web server started.

```

**Two questions:**

1. Has anybody else encountered this issue or have any ideas?
2. Is there are way to enable more verbose logging within the Neo4j docker that would help troubleshooting?

Thanks in advance for any ideas here.

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [April 26, 2020, 11:08pm UTC](https://community.neo4j.com/t/connect-to-neo4j-in-docker-from-python-in-a-different-docker-container/17641/2 "2020-04-26T23:08:18Z")

</div>

This isn't related to Neo4j, it's just how docker networking works. To fix this, you have to create a network and assign both of your containers to it, otherwise the containers can each talk to the host, but not to each other. This explains why it works from your host machine but not from the second docker container.

Here are the docker networking docs that will step you through how to do that.

> **[Basic Networking with Docker](https://runnable.com/docker/basic-docker-networking)**
>
> The fundamentals of container networking with Docker.
