Container health checks are small configuration details with large operational consequences. This guide explains how Docker HEALTHCHECK, Kubernetes readiness probes, liveness probes, and startup probes differ, then provides a reusable checklist for testing slow starts, dependency failures, timeouts, and graceful shutdowns without creating avoidable restarts or routing traffic to an unready application.
Overview
A health check should answer a specific operational question, not simply confirm that a process exists. Is the application ready to receive traffic? Is it alive but temporarily unable to serve? Is it still starting? The right answer determines which check to configure.
Docker's HEALTHCHECK defines a command that the container runtime can use to mark a container as healthy, unhealthy, or still waiting for its first result. It is useful for local development, standalone containers, and tools that understand Docker health status. A Docker health check does not automatically restart an unhealthy container in every environment; restart behavior depends on the runtime, orchestration layer, or an external automation rule.
Kubernetes separates the signals more deliberately:
| Mechanism | Primary question | Typical consequence of failure |
|---|---|---|
| Readiness probe | Can this container receive traffic now? | The Pod is removed from matching Service endpoints while it is not ready. |
| Liveness probe | Is the application functioning well enough to continue running? | Kubernetes may restart the container after the configured failure threshold. |
| Startup probe | Has the application completed its initial startup? | Startup checking gates liveness and readiness behavior until it succeeds. |
| Docker HEALTHCHECK | Does a command report that the container is healthy? | The container receives a health status; action depends on the surrounding platform. |
These checks are not interchangeable. A database outage, for example, may make an application unable to serve requests without meaning that the process is dead. Treating every dependency failure as a liveness failure can cause restart loops and make recovery harder.
Choose the signal before choosing the command
Use readiness for temporary conditions such as warming a cache, waiting for a required local resource, entering maintenance mode, or losing a dependency that is necessary for a particular request. Use liveness sparingly for failures the application cannot recover from internally. Use a startup probe when initialization is predictably slow or variable. A startup probe prevents a strict liveness policy from killing a process before it has had a reasonable chance to initialize.
Checklist by scenario
For a basic HTTP service
- Expose a lightweight health endpoint that does not perform expensive business work.
- Return a success status only when the application can perform the work the probe is intended to represent.
- Set the probe's port and path explicitly rather than relying on an accidental default.
- Test the endpoint from the same network and security context used by the container or Pod.
- Confirm that authentication, redirects, TLS requirements, and virtual-host routing do not produce a false failure.
A simple process-only endpoint may be appropriate for liveness, while readiness can check whether the service has completed initialization. Avoid making both probes depend on every downstream service unless a dependency failure genuinely means the process should be replaced.
For slow or variable startup
- Measure startup time under realistic image, CPU, storage, and dependency conditions.
- Add a startup probe instead of making liveness thresholds arbitrarily large.
- Give the startup probe enough failure budget to cover ordinary cold starts, but not an indefinite hang.
- After startup succeeds, verify that readiness becomes true only when traffic can be served safely.
- Test both a normal start and a start with a slow or unavailable dependency.
Kubernetes probe timing commonly includes initialDelaySeconds, periodSeconds, timeoutSeconds, successThreshold, and failureThreshold. Their effective behavior depends on the probe type and Kubernetes version, so check the documentation for the version and platform you operate. A useful failure budget is approximately the check period multiplied by the failure threshold, with startup delay and command execution time considered separately.
For dependency failures
- Decide whether the application can serve partial functionality when the dependency is unavailable.
- Use readiness to stop new traffic when requests would predictably fail.
- Keep liveness independent of recoverable dependency outages whenever possible.
- Log the dependency name, failure reason, and elapsed time without exposing credentials or sensitive payloads.
- Restore the dependency and confirm that readiness returns without requiring a process restart.
For Docker HEALTHCHECK
- Keep the check executable inside the image or invoke a command that is guaranteed to exist.
- Use an explicit interval, timeout, retry count, and startup grace period where supported by the target runtime.
- Make the command return a nonzero status only for a meaningful health failure.
- Run
docker inspector the equivalent runtime command to review status and recent check output. - Confirm how the deployment platform translates an unhealthy state into traffic removal, replacement, or no action.
For graceful shutdown
- Make the application respond correctly to the termination signal used by the runtime.
- Stop accepting new work before the process exits.
- Allow in-flight requests to finish within the termination grace period.
- Verify that readiness changes during shutdown rather than continuing to advertise the instance as available.
- Test rolling updates, manual deletion, and node interruption separately where practical.
What to double-check
Probe fields and behavior
Review the handler type: HTTP, TCP, command execution, or gRPC where supported by the platform and version. Confirm the command's exit codes, the HTTP status range treated as success, the selected host and port, and whether the timeout is long enough for normal load but short enough to detect a real stall. Check whether the configured success threshold is valid for the selected probe type and whether a startup probe changes when other probes begin running.
Also inspect the container's resource limits. CPU throttling, memory pressure, disk latency, certificate loading, migrations, and image extraction can make a valid health check exceed a narrowly chosen timeout. Increasing timeouts without investigating the cause can hide a capacity problem, while setting them too low can produce flapping.
Failure diagnosis checklist
- Read the container or Pod events and identify which probe failed.
- Compare probe failures with application logs and resource metrics.
- Run the same command manually inside an equivalent container.
- Check DNS, service discovery, network policy, and port bindings.
- Determine whether the failure is consistent, intermittent, or limited to startup.
- Inspect the previous container's termination reason if a restart occurred.
- Reproduce the condition with an intentionally slow response, refused connection, and dependency outage.
Keep health-check output concise. Detailed request traces belong in application logs or metrics, which can then be connected to the probe failure using timestamps and container identity. For related operational context, see the container log management guide.
Common mistakes
- Using liveness as readiness: A service that cannot serve traffic is not necessarily a service that should be restarted.
- Checking an expensive endpoint: Health checks can add load and fail because of work unrelated to basic availability.
- Ignoring startup time: A short liveness delay can repeatedly kill an application during migrations or cache construction.
- Assuming Docker health status controls orchestration: Verify what the actual deployment platform does with an unhealthy result.
- Hard-coding a tool that is absent: Minimal images may not contain shell utilities, curl, wget, or diagnostic clients.
- Checking localhost incorrectly: A service bound only to one interface, or a probe using the wrong address, can create misleading failures.
- Making readiness depend on every optional feature: This can remove healthy capacity for a nonessential subsystem.
- Forgetting shutdown behavior: A correct startup probe does not prevent dropped requests during termination.
- Changing thresholds without observing results: Record restart counts, readiness transitions, response latency, and recovery time after each change.
Probe configuration should also be reviewed alongside image and deployment changes. An image may remove a diagnostic binary, a framework update may alter startup time, or a port change may leave a previously valid check pointing at the wrong listener. The image verification checklist and Kubernetes upgrade checklist provide useful adjacent checks.
When to revisit
Revisit container health checks before a seasonal traffic increase, after a major application or framework update, when moving between runtimes or Kubernetes versions, and whenever startup time, dependency architecture, resource limits, or shutdown behavior changes. Review them after an incident involving restart loops, failed rollouts, elevated error rates, or traffic reaching an instance before it was ready.
Use this practical workflow:
- Write down what each signal is supposed to mean: ready, alive, or started.
- Record normal and worst-case startup times from representative environments.
- Test success, timeout, refused connection, malformed response, dependency outage, and graceful shutdown paths.
- Set thresholds from observed behavior, then leave enough margin for ordinary variation.
- Deploy the change gradually and watch readiness transitions, restarts, latency, and logs.
- Document the expected failure action so the next incident responder knows whether to repair, roll back, or wait.
Health checks are most valuable when they match the service's real operating contract. Treat them as versioned reliability configuration, not boilerplate copied between workloads. Rechecking that contract whenever workflows or tools change helps prevent both silent traffic failures and unnecessary container restarts.