Docker
/Advanced
Health Checks
Definition
An instruction added to a Dockerfile or Compose file that tells Docker how to test if the application running inside the container is actually functioning properly, not just whether the container process is running.
Explain Like I'm New
Checking the pulse of the app. Just because a web server container is turned 'On' doesn't mean the website isn't returning 500 Crash Errors. A health check actively pings the website every 30 seconds. If the site fails to load, Docker marks the container as 'Unhealthy'.
Real World Example
In a `docker-compose.yml`, you configure a health check to run `curl -f http://localhost/ || exit 1` every 30 seconds. A load balancer watches this status. If the container becomes 'Unhealthy', the load balancer automatically stops sending user traffic to it.
Common Use Cases
- •Zero-downtime deployments
- •Automated container restarts
- •Load balancer routing
Interview Questions
basic
- What does it mean if a container status says 'Up 5 hours (unhealthy)'?
intermediate
- Why is relying purely on the container's 'Running' state dangerous in production?