.NET › Docker & Containerization
What is a container health check (HEALTHCHECK instruction), and how does it differ from a Kubernetes liveness/readiness probe?
AdvancedAnswer
A Dockerfile's HEALTHCHECK instruction defines a command Docker itself periodically runs inside the container to determine if it's healthy, useful for basic container orchestrators or Docker Swarm, marking the container status as 'unhealthy' in `docker ps` output if it fails repeatedly. Kubernetes largely supersedes this with its own liveness/readiness probes configured at the Pod spec level (HTTP, TCP, or exec-based checks) rather than relying on the Dockerfile's HEALTHCHECK, since Kubernetes needs its own control over probe behavior for its scheduling and self-healing decisions -- when deploying to Kubernetes, the Dockerfile HEALTHCHECK is typically redundant or omitted in favor of Kubernetes-native probes.
# Dockerfile HEALTHCHECK (used by plain Docker/Swarm, often redundant in Kubernetes)
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:8080/health || exit 1
# Kubernetes equivalent, configured in the Pod spec instead:
livenessProbe:
httpGet: { path: /health/live, port: 8080 }
periodSeconds: 10Real-world example A team removes the Dockerfile HEALTHCHECK instruction from their images once fully migrating to Kubernetes, since it provided no value there and Kubernetes's own liveness/readiness probes already handle health monitoring more appropriately for that orchestration layer.