Main idea
Running means the process started. Healthy means the app is actually responding correctly.
This page covers one of the most important real-world Docker ideas: a container can be running while the application inside it is still not ready.
Running means the process started. Healthy means the app is actually responding correctly.
Startup order alone does not guarantee that databases, APIs, or apps are fully ready to accept traffic.
depends_on helps startup order, but it does not guarantee service readiness by itself.
HEALTHCHECK CMD curl --fail http://localhost:3000/health || exit 1
Docker calls a health endpoint and marks the container unhealthy if the check fails.
services:
app:
build: .
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:3000/health"]
interval: 10s
timeout: 5s
retries: 3
test defines the command Docker should run.interval defines how often Docker checks.timeout defines how long one check may take.retries defines how many failures happen before the container is marked unhealthy.depends_on alone.Next page: Lesson 11 explores Docker image optimization so your builds become smaller, cleaner, and faster.