I’m following along with this Docker/Django/Postgres quickstart tutorial and there’s a recurring issue with starting up the Postgres image. If I have my
docker-compose.yml file the way the tutorial has it, i.e.
version: '3' services: db: image: postgres web: build: . command: python3 manage.py runserver 0.0.0.0:8000 volumes: - .:/code ports: - "8000:8000" depends_on: - db
web process starts kicking in before the database is set up, and I get an error message like this:
web_1 | Is the server running on host "db" (172.19.0.2) and accepting web_1 | TCP/IP connections on port 5432?
followed by errors in the
db process that look like this:
db_1 | waiting for server to start....2018-01-31 04:42:44.584 UTC  LOG: listening on IPv4 address "127.0.0.1", port 5432 db_1 | 2018-01-31 04:42:44.584 UTC  LOG: could not bind IPv6 address "::1": Cannot assign requested address db_1 | 2018-01-31 04:42:44.584 UTC  HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry. db_1 | 2018-01-31 04:42:44.588 UTC  LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" db_1 | 2018-01-31 04:42:44.601 UTC  LOG: database system was shut down at 2018-01-31 04:42:43 UTC db_1 | 2018-01-31 04:42:44.608 UTC  LOG: database system is ready to accept connections db_1 | done
and my app doesn’t work. If I use the
wait-for-it.sh hack and replace the
command line with this:
command: ["./wait-for-it.sh", "db:5432", "--", "python3", "manage.py", "runserver", "0.0.0.0:8000"]
web process actually waits for the
db process, but I still get the same
db error initially, and it goes away when the process is restarted, so the app ends up working.
wait-for-it.sh thing feels really hacky, and I don’t feel like I should be seeing any of these error messages. How should I go about getting rid of those? I’m on a Mid 2012 Macbook Pro on OSX version 10.12.1 and Docker Version 17.12.0-ce-mac49 (21995) if that’s important.
Thanks in advance!