docker/cli ยท error
--health-retries cannot be negative
Error message
--health-retries cannot be negative
What it means
--health-retries sets how many consecutive probe failures mark the container unhealthy; the CLI rejects negative values before constructing the HealthConfig (opts.go:584-586). 0 means 'use the daemon default', so only values >= 0 are meaningful.
Source
Thrown at cli/command/container/opts.go:585
copts.healthStartInterval != 0
if copts.noHealthcheck {
if haveHealthSettings {
return nil, errors.New("--no-healthcheck conflicts with --health-* options")
}
healthConfig = &container.HealthConfig{Test: []string{"NONE"}}
} else if haveHealthSettings {
var probe []string
if copts.healthCmd != "" {
probe = []string{"CMD-SHELL", copts.healthCmd}
}
if copts.healthInterval < 0 {
return nil, errors.New("--health-interval cannot be negative")
}
if copts.healthTimeout < 0 {
return nil, errors.New("--health-timeout cannot be negative")
}
if copts.healthRetries < 0 {
return nil, errors.New("--health-retries cannot be negative")
}
if copts.healthStartPeriod < 0 {
return nil, errors.New("--health-start-period cannot be negative")
}
if copts.healthStartInterval < 0 {
return nil, errors.New("--health-start-interval cannot be negative")
}
healthConfig = &container.HealthConfig{
Test: probe,
Interval: copts.healthInterval,
Timeout: copts.healthTimeout,
StartPeriod: copts.healthStartPeriod,
StartInterval: copts.healthStartInterval,
Retries: copts.healthRetries,
}
}
View on GitHub (pinned to e9452d6e78)
Solutions
- Set a non-negative retry count, e.g. --health-retries=3
- Omit the flag (or 0) for the default retry count
- For effectively-infinite tolerance, use a large positive number rather than a negative sentinel
Example fix
# before docker run --health-cmd 'curl -f localhost' --health-retries=-1 myimage # after docker run --health-cmd 'curl -f localhost' --health-retries=5 myimage
When it happens
Trigger: `docker run --health-cmd '...' --health-retries=-1 image` on run/create, or any negative integer reaching the flag via script variable expansion.
Common situations: Using -1 hoping for 'retry forever'; off-by-one arithmetic in deployment scripts; copying sentinel conventions from other tools.
Related errors
- --health-interval cannot be negative
- --health-timeout cannot be negative
- --health-start-period cannot be negative
- --health-start-interval cannot be negative
- --pid: invalid PID mode
AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01).
Data as JSON: /data/errors/d4e5c6ee59cd4b5a.json.
Report an issue: GitHub.