Reputation: 3148
I run a docker instance of Neo4j :
docker run -d \
--publish=7474:7474 \
--publish=7687:7687 \
--volume=/home/jeff/tmp/neo4j:/data neo4j
The IP given with a "docker inspect" is : 172.17.0.2. I can connect to Neo4j into the browser, and change the password.
Then, start a bash instance in Docker :
docker run -it ubuntu:16.04 bash
apt-get update
apt-get install python3
apt-get install python3-pip
pip3 install neo4j-driver
apt-get install nano
nano test.py
The python script "test.py" is :
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from neo4j.v1 import GraphDatabase, basic_auth
session = GraphDatabase.driver(
'bolt://172.17.0.2',
auth=basic_auth('neo4j', '******')
).session()
session.run('MATCH (n) RETURN n')
Then :
chmod +x test.py
./test.py
I get this :
Traceback (most recent call last):
File "./test.py", line 11, in <module>
session.run('MATCH (n) RETURN n')
File "/usr/local/lib/python3.5/dist-packages/neo4j/v1/bolt.py", line 145, in run
self.connection.send()
File "/usr/local/lib/python3.5/dist-packages/neo4j/bolt/connection.py", line 344, in send
raise ServiceUnavailable("Failed to write to closed connection %r" % (self.server.address,))
neo4j.bolt.connection.ServiceUnavailable: Failed to write to closed connection Address(host='172.17.0.2', port=7687)
Outside of the container, i mean on the host machine, the test.py script works fine. Any idea ?
-- EDIT --
Inside the container, 'ip a' gives :
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
18: eth0@if19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:04 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.4/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:4/64 scope link
valid_lft forever preferred_lft forever
Upvotes: 3
Views: 3541
Reputation: 106
The IP inside the container "172.17.0.4", does not match the one you specify in the script, "172.17.0.2". I suspect Python attempted to bind to the latter, failed, and returned a closed socket. Then when Neo4j went to send, it errored on a closed socket. Search for "failed to write" on this page.
Try setting the script to use one of these as the address:
Upvotes: 2