depends_on
A Compose setting that makes one service start only after the services it needs.
In more detail
By default depends_on only waits for the other container to start, not to be ready. Add condition: service_healthy with a health check on the database so the API waits until the database actually accepts connections. Your application should still retry, because dependencies can restart later.
Example
depends_on:
db:
condition: service_healthyRelated terms
- health check — A regular automated test of whether a program or service is working, such as a request to its health endpoint or a command run inside its container.
- service — A long-running program that waits for and answers requests, such as a web API or a database; in Compose, one named entry under services.
- dependency — Anything a program needs in order to work, such as a library, a tool or another service.
Taught in
- Run, Stop, Restart And Remove A Container — Docker Architecture & Production Containers
- Build Context, Dockerignore And Your First Dockerfile — Docker Architecture & Production Containers
- Multi Stage Builds, Targets And Build Secrets — Docker Architecture & Production Containers
- Port Publishing, Localhost And Network Troubleshooting — Docker Architecture & Production Containers
- Define The Service And Database With Compose — Docker Architecture & Production Containers
- Health Checks, Dependencies And Reliable Startup — Docker Architecture & Production Containers
- From Local Containers To Kubernetes — Docker Architecture & Production Containers