Quiz Entry - updated: 2026.11.10
What does depends_on in Docker Compose guarantee, and what does it not?
It only controls start order (start db before wordpress), not readiness: the database may still be initialising when the dependent service starts. For readiness, combine a healthcheck with condition: service_healthy.
With plain depends_on: [db], Compose starts the db container first and the WordPress container right after. A container being started does not mean the program inside is ready: MySQL takes several seconds to initialise its data directory on first run. A dependent service that connects immediately can fail.
Ways to handle it:
services:
db:
image: mysql:8.4
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 5s
retries: 10
wordpress:
depends_on:
db:
condition: service_healthy
- The long form with
condition: service_healthymakes Compose wait until the db's health check passes. - Retry logic in the application (or
restart: always, so a crashed dependent simply tries again) covers the case anyway, and is needed in production, where a database can also restart later.
depends_on also affects shutdown: docker compose down stops dependents before their dependencies.
Go deeper:
Docker Docs: Control startup and shutdown order โ
service_healthyand the other conditions.