{"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/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/opts.go#L567-L603","documentation":"--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.","triggerScenarios":"`docker run --health-cmd '...' --health-retries=-1 image` on run/create, or any negative integer reaching the flag via script variable expansion.","commonSituations":"Using -1 hoping for 'retry forever'; off-by-one arithmetic in deployment scripts; copying sentinel conventions from other tools.","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"],"exampleFix":"# before\ndocker run --health-cmd 'curl -f localhost' --health-retries=-1 myimage\n# after\ndocker run --health-cmd 'curl -f localhost' --health-retries=5 myimage","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","healthcheck","flag-validation"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}