{"record":{"id":"84e1d65415cbbfc6","repo":"docker/cli","slug":"invalid-target-port-s-value-must-be-an-integer","errorCode":null,"errorMessage":"invalid target port (%s): value must be an integer: %w","messagePattern":"invalid target port \\((.+?)\\): value must be an integer: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/swarmopts/port.go","lineNumber":80,"sourceCode":"\t\t\t\t\tpConfig.Protocol = proto\n\t\t\t\tdefault:\n\t\t\t\t\treturn fmt.Errorf(\"invalid protocol value '%s'\", val)\n\t\t\t\t}\n\t\t\tcase portOptMode:\n\t\t\t\tswitch swarm.PortConfigPublishMode(val) {\n\t\t\t\tcase swarm.PortConfigPublishModeIngress, swarm.PortConfigPublishModeHost:\n\t\t\t\t\tpConfig.PublishMode = swarm.PortConfigPublishMode(val)\n\t\t\t\tdefault:\n\t\t\t\t\treturn fmt.Errorf(\"invalid publish mode value (%s): must be either '%s' or '%s'\", val, swarm.PortConfigPublishModeIngress, swarm.PortConfigPublishModeHost)\n\t\t\t\t}\n\t\t\tcase portOptTargetPort:\n\t\t\t\ttPort, err := strconv.ParseUint(val, 10, 16)\n\t\t\t\tif err != nil {\n\t\t\t\t\tvar numErr *strconv.NumError\n\t\t\t\t\tif errors.As(err, &numErr) {\n\t\t\t\t\t\terr = numErr.Err\n\t\t\t\t\t}\n\t\t\t\t\treturn fmt.Errorf(\"invalid target port (%s): value must be an integer: %w\", val, err)\n\t\t\t\t}\n\n\t\t\t\tpConfig.TargetPort = uint32(tPort)\n\t\t\tcase portOptPublishedPort:\n\t\t\t\tpPort, err := strconv.ParseUint(val, 10, 16)\n\t\t\t\tif err != nil {\n\t\t\t\t\tvar numErr *strconv.NumError\n\t\t\t\t\tif errors.As(err, &numErr) {\n\t\t\t\t\t\terr = numErr.Err\n\t\t\t\t\t}\n\t\t\t\t\treturn fmt.Errorf(\"invalid published port (%s): value must be an integer: %w\", val, err)\n\t\t\t\t}\n\n\t\t\t\tpConfig.PublishedPort = uint32(pPort)\n\t\t\tdefault:\n\t\t\t\treturn fmt.Errorf(\"invalid field key: %s\", key)\n\t\t\t}\n\t\t}","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/swarmopts/port.go#L62-L98","documentation":"Thrown by PortOpt.Set (port.go:80) when the `target` (container) port value cannot be parsed as an unsigned 16-bit integer (0–65535). strconv.ParseUint(val, 10, 16) fails on non-numeric, out-of-range, or empty values; the underlying NumError is unwrapped via errors.As and wrapped into this message.","triggerScenarios":"Passing `--publish target=abc`, `target=70000` (exceeds uint16), `target=-1`, or `target=` (empty). ParseUint returns an error, errors.As extracts the NumError, and line 80 reports it.","commonSituations":"Typos, values exceeding 65535, negative numbers, empty strings from variable expansion, or confusion between the target (container) and published (host) port slots.","solutions":["Provide an integer between 0 and 65535 for target: `--publish target=80`.","Ensure the value is a plain decimal integer with no units or sign for negative.","Pre-validate with `strconv.ParseUint(val, 10, 16)`.","Remember target= is the in-container port; published= is the host port."],"exampleFix":"// before\n--publish published=8080,target=80http\n// after\n--publish published=8080,target=80","handlingStrategy":"validation","validationCode":"// Validate the target port as a uint16 before Set.\nif _, err := strconv.ParseUint(targetVal, 10, 16); err != nil {\n    return fmt.Errorf(\"target port %q must be an integer 0-65535\", targetVal)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Target port must be 0–65535, plain decimal.","Remember target = container port, published = host port.","Strip units/signs/whitespace.","Pre-validate with strconv.ParseUint(val, 10, 16)."],"tags":["docker","swarm","port","validation","networking","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}