I have the following containers running:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b02d801f9aa3 development_mongo "docker-entrypoint.s…" 7 hours ago Up About an hour 0.0.0.0:50001->27017/tcp compose_mongo
2903bb830ea7 development_postgres "docker-entrypoint.s…" 7 hours ago Up About an hour 0.0.0.0:50000->5432/tcp compose_postgres
6ce3fe015a8f development_elastic "/usr/local/bin/dock…" 7 hours ago Up About an hour 0.0.0.0:50002->9200/tcp, 0.0.0.0:50003->9300/tcp compose_elastic
When I create/run a Docker container that has python manage.py makemigrations
as entrypoint, the Django app can't connect to the Postgres container:
$ docker run --name test1 repo/myapp:stage_1605191501
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "0.0.0.0" and accepting
TCP/IP connections on port 50000?
Why it cannot connect, since that Postgres port is already exposed to the host? What am I missing?