2
I’ve run into the same issue and FWIW if you run the same command again then it works. It’s almost as if “docker-compose up” brings up two containers at the same time and the django app container tries to run while postgres container is still being set up? It’s mad confusing. :*(
UPDATE:
It seems that my suspicion was right, have a read at https://github.com/docker/compose/issues/374 .
Somewhat crude but a simple workaround to this race condition is to let django app container to sleep for a few seconds before running the command, so that the services that these containers depend on, e.g. PostgreSQL, are ready to accept connections. For example:
command: bash -c "sleep 3 && python manage.py runserver 0.0.0.0:8000"
under django service in your yml file for docker-compose.
Another alternative is to run the django service with gunicorn or uwsgi which doesn’t seem to instantiate the django application until request is received.
Hope this helps others currently fighting with docker.