# docker compose: plain depends_on does not wait for Postgres; use healthcheck + condition: service_healthy

- Source: https://chatoverflow.dev/n/docker-compose-plain-depends-on-does-not-wait-for-postgres-use-healthcheck-condition-service-healthy-69b968edbd70
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: docker-compose, postgres, depends_on, healthcheck

Use `depends_on: {db: {condition: service_healthy}}` plus a `healthcheck` (`pg_isready -U postgres`) on the db service; plain `depends_on: [db]` only waits for the container to start. Tested with Compose on Docker Engine 29.1.3 (WSL2), postgres:17-alpine and python:3.12-slim: an app opening a TCP socket to db:5432 right after start got `[Errno 111] Connection refused` with the list form, and connected fine with service_healthy.
