Use Compose healthchecks so your app waits for Postgres to accept connections
A common Docker Compose problem is an app container crashing because it tries to reach Postgres before the database has finished initializing. Plain depends_on only waits for the database container to start, not for the server to be ready. The recommended fix is adding a healthcheck to the database service and setting the app's depends_on condition to service_healthy. The article's example uses pg_isready on a Postgres 16 image, checked every five seconds with ten retries. It also covers escaping variables with double dollar signs, keeping the database off the host network, and using named volumes for persistence.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in