{"record":{"id":"1a45d9c1bdcd673d","repo":"docker/cli","slug":"health-interval-cannot-be-negative","errorCode":null,"errorMessage":"--health-interval cannot be negative","messagePattern":"--health-interval cannot be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":579,"sourceCode":"\tvar healthConfig *container.HealthConfig\n\thaveHealthSettings := copts.healthCmd != \"\" ||\n\t\tcopts.healthInterval != 0 ||\n\t\tcopts.healthTimeout != 0 ||\n\t\tcopts.healthStartPeriod != 0 ||\n\t\tcopts.healthRetries != 0 ||\n\t\tcopts.healthStartInterval != 0\n\tif copts.noHealthcheck {\n\t\tif haveHealthSettings {\n\t\t\treturn nil, errors.New(\"--no-healthcheck conflicts with --health-* options\")\n\t\t}\n\t\thealthConfig = &container.HealthConfig{Test: []string{\"NONE\"}}\n\t} else if haveHealthSettings {\n\t\tvar probe []string\n\t\tif copts.healthCmd != \"\" {\n\t\t\tprobe = []string{\"CMD-SHELL\", copts.healthCmd}\n\t\t}\n\t\tif copts.healthInterval < 0 {\n\t\t\treturn nil, errors.New(\"--health-interval cannot be negative\")\n\t\t}\n\t\tif copts.healthTimeout < 0 {\n\t\t\treturn nil, errors.New(\"--health-timeout cannot be negative\")\n\t\t}\n\t\tif copts.healthRetries < 0 {\n\t\t\treturn nil, errors.New(\"--health-retries cannot be negative\")\n\t\t}\n\t\tif copts.healthStartPeriod < 0 {\n\t\t\treturn nil, errors.New(\"--health-start-period cannot be negative\")\n\t\t}\n\t\tif copts.healthStartInterval < 0 {\n\t\t\treturn nil, errors.New(\"--health-start-interval cannot be negative\")\n\t\t}\n\n\t\thealthConfig = &container.HealthConfig{\n\t\t\tTest:          probe,\n\t\t\tInterval:      copts.healthInterval,\n\t\t\tTimeout:       copts.healthTimeout,","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/opts.go#L561-L597","documentation":"Returned when --health-interval is set to a negative duration (opts.go:578-580). The flag is registered with flags.DurationVar (opts.go:264), so Go's duration parser accepts values like \"-5s\". A negative interval between health checks is nonsensical, so it is rejected only when haveHealthSettings is true.","triggerScenarios":"Running `docker run --health-interval=-5s ...` or any value that parses to a negative time.Duration, while at least one health setting is present. A leading minus sign on the duration triggers it.","commonSituations":"A leading `-` typo when editing scripts; variable expansion producing `-<value>`; misunderstanding that 0 means default and trying to pass a negative to mean \"faster\".","solutions":["Use a positive duration like --health-interval=30s.","Use 0 (or omit the flag) to accept the daemon default interval.","Check shell variable expansion is not prepending a stray minus sign."],"exampleFix":"// before\ndocker run --health-interval=-5s --health-cmd=/check.sh myimage\n// after\ndocker run --health-interval=5s --health-cmd=/check.sh myimage","handlingStrategy":"validation","validationCode":"if copts.healthInterval < 0 {\n    return errors.New(\"--health-interval cannot be negative\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanitize duration strings for a leading minus before passing them.","Use 0 to mean daemon default, not a negative value.","Add a linter rule for negative durations in health flags."],"tags":["docker-cli","healthcheck","duration","negative-value","validation","container-create"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}