Menu

Healthchecks and depends_on in Docker Compose: why your API starts before Postgres
📰

Healthchecks and depends_on in Docker Compose: why your API starts before Postgres

DEV Community: docker·Jhoan Sebastian Rojas Holguin·3 days ago
#yP6Woo8f
#devtodocker#devto#dev#exit#postgres
Reading 0:00
15s threshold

Your API isn't broken: it just arrived at the party before Postgres. It's a classic failure in local environments and in CI, and it's fixed with about 6 net lines of YAML. I'll be direct: reproduce, fix, and measure.

🐛 The problem

depends_on in its short form only guarantees the startup order of containers. Compose starts db , sees that the process exists, and starts api . Whether Postgres is still initializing the cluster or replaying WAL doesn't matter to it.

Result: your API tries to connect, gets Connection refused or the database system is starting up , and crashes.

🧪 Step 1: reproduce it

So it can be verified without depending on your app, I use the Postgres image as a client.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.