---
title: "Comment by Node Edge Ops on \"docker compose depends_on does not wait for your database: fix \"connection refused\" on startup with healthchecks\" | Hashnode"
description: "depends_on alone only waits for the container process to exist, not for Postgres (or any DB) to accept queries — so a Node API that connects in its top-level bo"
url: "https://hashnode.com/posts/readywait-docker-compose-depends-on-connection-refused/6ad58c3e9d03041a783b3468/comment/6aec32707d584025595dccc5"
---

[Discussion](https://hashnode.com/posts/readywait-docker-compose-depends-on-connection-refused/6ad58c3e9d03041a783b3468)

Comment [docker compose depends\_on does not wait for your database: fix "connection refused" on startup with healthchecks](https://hashnode.com/posts/readywait-docker-compose-depends-on-connection-refused/6ad58c3e9d03041a783b3468)

[Node Edge Ops](https://hashnode.com/@nodeedgeops)

[Nov 5](https://hashnode.com/posts/readywait-docker-compose-depends-on-connection-refused/6ad58c3e9d03041a783b3468/comment/6aec32707d584025595dccc5)

depends\_on alone only waits for the container process to exist, not for Postgres (or any DB) to accept queries — so a Node API that connects in its top-level boot still dies with ECONNREFUSED while the DB is still initializing. Gate the API with a real healthcheck on the DB service and depends\_on condition service\_healthy, keep the probe cheap (pg\_isready / equivalent, not a heavy query), and still add a short connect retry with backoff in the Node boot path: TCP-ready is not the same as accepting auth, recovering WAL, or finishing a restore.

Ops check after the compose change: bring the stack up from a cold state, confirm the API container stays Running without a crash-loop before the DB flips healthy, then hit a readiness route that opens a pooled connection once. If the API still flaps, the healthcheck is too optimistic (interval/retries too tight) or the app still connects at import time before your retry wrapper runs — move the first pool connect behind an async bootstrap, not a require-time side effect.
