Docker
HEALTHCHECK
livenessProbe
readinessProbe
container orchestration

Docker HEALTHCHECK vs Kubernetes livenessProbe and readinessProbe

Codemia Knowledge Hub ·

Docker HEALTHCHECK lets the container runtime mark a container as healthy or unhealthy. Kubernetes probes decide whether a Pod should receive traffic (readinessProbe) or be restarted (livenessProbe). If you run in Kubernetes, the probes in the Pod spec are usually the ones that matter operationally.

What Docker HEALTHCHECK does

A HEALTHCHECK is defined in the image or container configuration:

dockerfile
HEALTHCHECK --interval=30s --timeout=3s --retries=3   CMD curl -f http://localhost:8080/health || exit 1

Docker then records whether the container is healthy, starting or unhealthy. It is image-level metadata and runtime behavior inside the Docker ecosystem, useful for:

  • plain docker run
  • Docker Compose
  • local development
  • tooling that reads container health state directly

What livenessProbe does

A livenessProbe answers: "Should Kubernetes restart this container because it appears broken?"

yaml
1livenessProbe:
2  httpGet:
3    path: /health/live
4    port: 8080
5  initialDelaySeconds: 10
6  periodSeconds: 10

If it fails repeatedly, Kubernetes restarts the container.

What readinessProbe does

A readinessProbe answers: "Is this container ready to receive traffic right now?"

yaml
1readinessProbe:
2  httpGet:
3    path: /health/ready
4    port: 8080
5  initialDelaySeconds: 5
6  periodSeconds: 5

If readiness fails, the Pod keeps running but is removed from Service endpoints until it is ready again. Readiness affects traffic; liveness affects restarts.

Why to define probes in the Pod spec

Kubernetes does not treat a Docker HEALTHCHECK in the image as a substitute for explicit probes. If the workload runs in Kubernetes, define health behavior in the Pod spec, where orchestration policy belongs, so deployment-specific health rules stay with the deployment.

startupProbe for slow-booting apps

Use a startupProbe when the application takes a long time to initialize and you do not want liveness checks to kill it early:

yaml
1startupProbe:
2  httpGet:
3    path: /health/startup
4    port: 8080
5  periodSeconds: 5
6  failureThreshold: 30

This is often a better fix than stretching liveness timings a lot.

Which check to use when

Use Docker HEALTHCHECK when:

  • the container is mainly run with Docker tools
  • you want image-local health metadata
  • you are working outside Kubernetes

Use readinessProbe when:

  • the app may be alive but temporarily unable to serve requests
  • you want safe rollouts and traffic gating

Use livenessProbe when:

  • the app can get stuck in a bad state and should be restarted automatically

Health check mistakes that cause outages or restart loops

  • One endpoint for readiness and liveness. A dependency outage may mean "stop sending traffic" but not "restart the process."
  • Relying on Docker HEALTHCHECK alone in Kubernetes. Define probe behavior explicitly.
  • Aggressive liveness probes. They create restart loops for apps that are merely slow to start; a startupProbe is often the right fix.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design