Skip to content

Commit f12e708

Browse files
committed
Update documentation
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 2f1d258 commit f12e708

File tree

1 file changed

+53
-30
lines changed

1 file changed

+53
-30
lines changed

docs/healthchecks.md

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,74 @@
11
# Health Check Support in nerdctl
22

3-
`nerdctl` supports Docker-compatible health checks for containers, allowing users to monitor container health via a user-defined command.
3+
`nerdctl` supports Docker-compatible health checks for containers, allowing you to monitor container health through user-defined commands.
44

5-
Currently, health checks can be triggered manually using the nerdctl container healthcheck command. Automatic orchestration (e.g., periodic checks) will be added in a future update.
5+
## Configuration Options
66

77
Health checks can be configured in multiple ways:
88

9-
1. At container creation time using nerdctl run or nerdctl create with `--health-*` flags
9+
1. At container creation time using `nerdctl run` or `nerdctl create` with these flags:
10+
- `--health-cmd`: Command to run to check health
11+
- `--health-interval`: Time between running the check (default: 30s)
12+
- `--health-timeout`: Maximum time to allow one check to run (default: 30s)
13+
- `--health-retries`: Consecutive failures needed to report unhealthy (default: 3)
14+
- `--health-start-period`: Start period for the container to initialize before starting health-retries countdown
15+
- `--no-healthcheck`: Disable any container-specified HEALTHCHECK
16+
1017
2. At image build time using HEALTHCHECK in a Dockerfile
11-
3. In docker-compose.yaml files, if using nerdctl compose
18+
3. In docker-compose.yaml files when using nerdctl compose
1219

13-
When a container is created, nerdctl determines the health check configuration based on the following priority:
20+
## Configuration Priority
1421

15-
1. **CLI flags** take highest precedence (e.g., `--health-cmd`, etc.)
16-
2. If no CLI flags are set, nerdctl will use any health check defined in the image.
17-
3. If neither is present, no health check will be configured
22+
When a container is created, nerdctl determines the health check configuration based on this priority:
1823

19-
Example:
24+
1. CLI flags take highest precedence (e.g., `--health-cmd`, etc.)
25+
2. If no CLI flags are set, nerdctl will use any health check defined in the image
26+
3. If neither is present, no health check will be configured
2027

21-
```bash
22-
nerdctl run --name web --health-cmd="curl -f http://localhost || exit 1" --health-interval=30s --health-timeout=5s --health-retries=3 nginx
23-
```
28+
## Automatic Health Checks with systemd
2429

25-
### Disabling Health Checks
30+
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.
2631

27-
You can disable health checks using the following flag during container create/run:
32+
### Requirements for Automatic Health Checks
2833

29-
```bash
30-
--no-healthcheck
31-
```
34+
- systemd must be available on the system
35+
- Container must not be running in rootless mode
36+
- Environment variable `DISABLE_HC_SYSTEMD` must not be set to "true"
3237

33-
### Running Health Checks Manually
38+
### How It Works
3439

35-
nerdctl provides a container healthcheck command that can be manually triggered by the user. This command runs the
36-
configured health check inside the container and reports the result. It serves as the entry point for executing
37-
health checks, especially in scenarios where external scheduling is used.
40+
1. When a container with health checks is created, nerdctl:
41+
- Creates a systemd timer unit for the container
42+
- Configures the timer according to the health check interval
43+
- Starts monitoring the container's health status
3844

39-
Example:
45+
2. The health check status can be one of:
46+
- `starting`: During container initialization
47+
- `healthy`: When health checks are passing
48+
- `unhealthy`: After specified number of consecutive failures
49+
## Examples
4050

41-
```
42-
nerdctl container healthcheck <container-id>
51+
1. Basic health check that verifies a web server:
52+
```bash
53+
nerdctl run -d --name web \
54+
--health-cmd="curl -f http://localhost/ || exit 1" \
55+
--health-interval=5s \
56+
--health-retries=3 \
57+
nginx
4358
```
4459

45-
### Future Work (WIP)
60+
2. Health check with initialization period:
61+
```bash
62+
nerdctl run -d --name app \
63+
--health-cmd="./health-check.sh" \
64+
--health-interval=30s \
65+
--health-timeout=10s \
66+
--health-retries=3 \
67+
--health-start-period=60s \
68+
myapp
69+
```
4670

47-
Since nerdctl is daemonless and does not have a persistent background process, we rely on systemd(or external schedulers)
48-
to invoke nerdctl container healthcheck at configured intervals. This allows periodic health checks for containers in a
49-
systemd-based environment. We are actively working on automating health checks, where we will listen to container lifecycle
50-
events and generate appropriate systemd service and timer units. This will enable nerdctl to support automated,
51-
Docker-compatible health checks by leveraging systemd for scheduling and lifecycle integration.
71+
3. Disable health checks:
72+
```bash
73+
nerdctl run --no-healthcheck myapp
74+
```

0 commit comments

Comments
 (0)