{"record":{"id":"d4e5c6ee59cd4b5a","repo":"docker/cli","slug":"health-retries-cannot-be-negative","errorCode":null,"errorMessage":"--health-retries cannot be negative","messagePattern":"--health-retries cannot be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":585,"sourceCode":"\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,\n\t\t\tStartPeriod:   copts.healthStartPeriod,\n\t\t\tStartInterval: copts.healthStartInterval,\n\t\t\tRetries:       copts.healthRetries,\n\t\t}\n\t}\n","sourceCodeStart":567,"sourceCodeEnd":603,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/opts.go#L567-L603","documentation":"Returned when --health-retries is set to a negative integer (opts.go:584-586). The flag is registered with flags.IntVar (opts.go:265), so values like -3 parse successfully. A negative consecutive-failure count is meaningless and rejected inside the haveHealthSettings branch.","triggerScenarios":"Running `docker run --health-retries=-3 ...` or any negative int, while health settings are present. Triggered by a literal negative value or a negative variable.","commonSituations":"Shell/compose variable resolving to a negative number; arithmetic bug computing retries; confusion with flags like --pids-limit that treat -1 as unlimited (health-retries has no such convention).","solutions":["Use a non-negative integer like --health-retries=3.","Use 0 (or omit) for the daemon default.","Do not use -1; it is not special for health-retries."],"exampleFix":"// before\ndocker run --health-retries=-1 --health-cmd=/check.sh myimage\n// after\ndocker run --health-retries=3 --health-cmd=/check.sh myimage","handlingStrategy":"validation","validationCode":"if copts.healthRetries < 0 {\n    return errors.New(\"--health-retries cannot be negative\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp retries to >= 0 in config generators.","Remember -1 is NOT unlimited here (unlike --pids-limit).","Validate integer inputs before runtime."],"tags":["docker-cli","healthcheck","integer","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"}