I've got a database (Neo4J) loading in a Docker container, but I think my unit test hits the container before the database is loaded.
def setUp(self):
client = docker.from_env()
self.container = client.containers.run("neo4j",
detach=True,
environment={'NEO4J_AUTH':'none'},
ports={7474:7474, 7687:7687},
volumes={'/Users/myuser/neo4j/data': {'bind': '/data', 'mode': 'rw'}}
)
self.container.start()
def test_database_loads(self):
r = requests.get(self.database_url)
self.assertEqual(r.status_code, 400)
I get this error:
======================================================================
ERROR: test_database_loads (backend.api.tests.test_base.BaseTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/aljabear/.pyenv/versions/visualist/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 386, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/Users/aljabear/.pyenv/versions/visualist/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 382, in _make_request
httplib_response = conn.getresponse()
File "/Users/aljabear/.pyenv/versions/3.5.3/lib/python3.5/http/client.py", line 1198, in getresponse
response.begin()
File "/Users/aljabear/.pyenv/versions/3.5.3/lib/python3.5/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/Users/aljabear/.pyenv/versions/3.5.3/lib/python3.5/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/Users/aljabear/.pyenv/versions/3.5.3/lib/python3.5/socket.py", line 576, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out
...etc. Basically my request times out.
I think my environment is OK; if I leave the container running, I can access it later on via curl.
My hunch is that I'm pinging the container before Neo4J gets started. Is there any way to force Dockerpy to wait until a container-hosted script is up and running?
Thanks