docker/cli · error

--health-timeout cannot be negative

Error message

--health-timeout cannot be negative

What it means

Returned when --health-timeout is set to a negative duration (opts.go:581-583). Registered via flags.DurationVar (opts.go:266), the flag accepts parsed negative durations which are then rejected as invalid. The check runs only within the haveHealthSettings branch.

Solutions

  1. Use a positive duration like --health-timeout=5s.
  2. Use 0 (or omit) for the daemon default timeout.
  3. Audit template arithmetic that may produce negative durations.

Example fix

// before
docker run --health-timeout=-2s --health-cmd=/check.sh myimage
// after
docker run --health-timeout=2s --health-cmd=/check.sh myimage
Defensive patterns

Strategy: validation

Validate before calling

if copts.healthTimeout < 0 {
    return errors.New("--health-timeout cannot be negative")
}

Prevention

When it happens

Trigger: Running `docker run --health-timeout=-2s ...` or any negative duration while health settings are present. The parser accepts the value, the guard rejects it.

Common situations: Typo'd minus sign in CI/CD variable; misreading documentation and passing a negative to mean "no timeout" (use 0 instead); templating that computes timeout as a negative delta.

Understand the failure class

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/f4741877a7c9d11f. Report an issue: GitHub.

Appendix: source

Thrown at cli/command/container/opts.go:582

		copts.healthTimeout != 0 ||
		copts.healthStartPeriod != 0 ||
		copts.healthRetries != 0 ||
		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 4f84911bfe)