healthcheck command validates that a container image has a healthcheck defined. Healthchecks allow Docker, Kubernetes, and other orchestrators to monitor container health and restart failed containers automatically.
Usage
Description
Thehealthcheck command checks if the image configuration includes a healthcheck instruction. It validates that:
- A healthcheck section exists in the image configuration
- The healthcheck test command is not empty
- The healthcheck is not explicitly disabled (
NONE)
- Enable automatic container health monitoring
- Support orchestrator health probes (Docker, Kubernetes)
- Detect failed or unhealthy containers
- Improve application reliability
- Comply with operational best practices
Flags
Output format:
text or jsonShort form: -oColor output mode:
auto, always, neverSet log level: trace, debug, info, warn, error, fatal, panic
Examples
Basic usage
Check custom image
Check OCI layout
Check OCI archive
JSON output
Output
Text Format
When validation passes:JSON Format
Exit Codes
| Code | Meaning | Example |
|---|---|---|
| 0 | Image has a valid healthcheck | HEALTHCHECK CMD curl -f http://localhost/ |
| 1 | Image has no healthcheck or healthcheck is disabled | No HEALTHCHECK instruction or HEALTHCHECK NONE |
| 2 | Execution error | Image not found |
Configuration
When using theall command, include healthcheck in your config file:
healthcheck check has no additional configuration options.
Implementation Details
- Reads
config.Config.Healthcheckfrom the image configuration - Passes if healthcheck exists, has non-empty test, and test is not
["NONE"] - Fails if healthcheck is nil, empty, or explicitly disabled
- Does not validate the healthcheck command syntax
- Does not test if the healthcheck actually works
Common Issues
No healthcheck defined
HEALTHCHECK instruction.
Solution: Add a HEALTHCHECK instruction to your Dockerfile:
Healthcheck explicitly disabled
Some Dockerfiles explicitly disable healthchecks inherited from base images:HEALTHCHECK NONE and define a proper healthcheck.
Base image has no healthcheck
Most official base images don’t include healthchecks:Best Practices
Define healthchecks for all production images
Use lightweight health check commands (avoid heavy operations)
Set appropriate intervals and timeouts for your application
Test healthchecks locally before deploying
Use HTTP endpoints for web applications
Dockerfile Examples
HTTP health check
TCP health check
Script-based health check
Application-specific health check
Healthcheck Parameters
| Parameter | Description | Default |
|---|---|---|
--interval | Time between health checks | 30s |
--timeout | Maximum time for check to complete | 30s |
--start-period | Grace period before checks start | 0s |
--retries | Consecutive failures before marking unhealthy | 3 |
Docker and Kubernetes Integration
Docker
Docker automatically runs healthchecks and updates container status:Kubernetes
Kubernetes doesn’t use Docker healthchecks directly, but you can define similar probes:check-image healthcheck ensures your images have Docker-native health monitoring, which can be useful for local development and Docker Compose deployments.
Exit Status in Healthcheck Commands
The healthcheck command should:- Exit with status
0if the container is healthy - Exit with status
1(or any non-zero) if the container is unhealthy
Related Commands
all- Run all checks including healthcheck validationentrypoint- Validate entrypoint configurationroot-user- Validate non-root user configuration