docs/healthchecks.md
nerdctl supports Docker-compatible health checks for containers, allowing users to monitor container health via a user-defined command.
| :zap: Requirement | nerdctl >= 2.1.5 |
|---|
Health checks can be configured in multiple ways:
At container creation time using nerdctl run or nerdctl create with these flags:
--health-cmd: Command to run to check health--health-interval: Time between running the check (default: 30s)--health-timeout: Maximum time to allow one check to run (default: 30s)--health-retries: Consecutive failures needed to report unhealthy (default: 3)--health-start-period: Start period for the container to initialize before starting health-retries countdown--no-healthcheck: Disable any container-specified HEALTHCHECKAt image build time using HEALTHCHECK in a Dockerfile
Note: The --health-start-interval option is currently not supported by nerdctl.
When a container is created, nerdctl determines the health check configuration based on this priority:
--health-cmd, etc.)You can disable health checks using the following flag during container create/run:
--no-healthcheck
nerdctl provides a container healthcheck command that can be manually triggered by the user. This command runs the configured health check inside the container and reports the result. It serves as the entry point for executing health checks, especially in scenarios where external scheduling is used.
Example:
nerdctl container healthcheck <container-id>
On Linux systems with systemd, nerdctl automatically creates and manages systemd timer units to execute health checks at the configured intervals. This provides reliable scheduling and execution of health checks without requiring a persistent daemon.
disable_hc_systemd must not be set to true in nerdctl.tomlWhen a container with health checks is created, nerdctl:
The health check status can be one of:
starting: During container initializationhealthy: When health checks are passingunhealthy: After specified number of consecutive failuresnerdctl run -d --name web \
--health-cmd="curl -f http://localhost/ || exit 1" \
--health-interval=5s \
--health-retries=3 \
nginx
nerdctl run -d --name app \
--health-cmd="./health-check.sh" \
--health-interval=30s \
--health-timeout=10s \
--health-retries=3 \
--health-start-period=60s \
myapp
nerdctl run --no-healthcheck myapp