{"record":{"id":"ad66a5bdf8cb6503","repo":"docker/cli","slug":"invalid-value-d-valid-memory-swappiness-range-i","errorCode":null,"errorMessage":"invalid value: %d. Valid memory swappiness range is 0-100","messagePattern":"invalid value: (.+?)\\. Valid memory swappiness range is 0-100","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":368,"sourceCode":"\tif copts.macAddress != \"\" {\n\t\tif _, err := net.ParseMAC(strings.TrimSpace(copts.macAddress)); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"%s is not a valid mac address\", copts.macAddress)\n\t\t}\n\t}\n\tif copts.stdin {\n\t\tattachStdin = true\n\t}\n\t// If -a is not set, attach to stdout and stderr\n\tif copts.attach.Len() == 0 {\n\t\tattachStdout = true\n\t\tattachStderr = true\n\t}\n\n\tvar err error\n\n\tswappiness := copts.swappiness\n\tif swappiness != -1 && (swappiness < 0 || swappiness > 100) {\n\t\treturn nil, fmt.Errorf(\"invalid value: %d. Valid memory swappiness range is 0-100\", swappiness)\n\t}\n\n\tvar binds []string\n\tvolumes := copts.volumes.GetMap()\n\t// add any bind targets to the list of container volumes\n\tfor bind := range volumes {\n\t\tparsed, err := volumespec.Parse(bind)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tif parsed.Source != \"\" {\n\t\t\ttoBind := bind\n\n\t\t\tif parsed.Type == string(mount.TypeBind) {\n\t\t\t\tif hostPart, targetPath, ok := strings.Cut(bind, \":\"); ok {\n\t\t\t\t\tif !filepath.IsAbs(hostPart) && strings.HasPrefix(hostPart, \".\") {\n\t\t\t\t\t\tif absHostPart, err := filepath.Abs(hostPart); err == nil {","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/opts.go#L350-L386","documentation":"Returned in opts.go:368 when --memory-swappiness is set to a value outside the documented kernel range. The sentinel -1 (meaning inherit) is allowed; any other value below 0 or above 100 is rejected.","triggerScenarios":"`docker run --memory-swappiness N` with N not in [0,100] and not -1 (e.g. 150, -2).","commonSituations":"Confusing swappiness scale with a 0-255 kernel scale, copy-pasting a value from a different tool, or a negative value other than -1.","solutions":["Use a value between 0 and 100 inclusive.","Use -1 only to inherit the host setting.","If unsure, omit the flag to use the daemon default."],"exampleFix":"# before\ndocker run --memory-swappiness 150 alpine\n\n# after\ndocker run --memory-swappiness 60 alpine","handlingStrategy":"validation","validationCode":"func validSwappiness(v int) bool { return v == -1 || (v >= 0 && v <= 100) }\nif !validSwappiness(swappiness) {\n    return fmt.Errorf(\"memory swappiness %d out of range [0,100] or -1\", swappiness)\n}","typeGuard":"func isValidSwappiness(v int) bool {\n    return v == -1 || (v >= 0 && v <= 100)\n}","tryCatchPattern":"// Range check is deterministic; correct the value, no retry.\nif !isValidSwappiness(v) { v = defaultSwappiness }","preventionTips":["Remember the scale is 0-100 (not the kernel 0-255).\nUse -1 to inherit, omit otherwise.","Validate in wrappers before invoking docker."],"tags":["container","memory","flag-validation","create"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}