{"record":{"id":"aca7dc1a934be6ee","repo":"docker/cli","slug":"invalid-published-port-s-value-must-be-an-inte","errorCode":null,"errorMessage":"invalid published port (%s): value must be an integer: %w","messagePattern":"invalid published port \\((.+?)\\): value must be an integer: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/swarmopts/port.go","lineNumber":91,"sourceCode":"\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}\n\n\t\tif pConfig.TargetPort == 0 {\n\t\t\treturn fmt.Errorf(\"missing mandatory field '%s'\", portOptTargetPort)\n\t\t}\n\n\t\tp.ports = append(p.ports, pConfig)\n\t} else {\n\t\t// short syntax ([ip:]public:private[/proto])\n\t\t//\n\t\t// TODO(thaJeztah): we need an equivalent that handles the \"ip-address\" part without depending on the nat package.\n\t\tports, portBindingMap, err := nat.ParsePortSpecs([]string{value})","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/swarmopts/port.go#L73-L109","documentation":"Thrown by PortOpt.Set (port.go:91) when the `published` (host) port value cannot be parsed as an unsigned 16-bit integer. Same logic as the target-port check: strconv.ParseUint(val, 10, 16) on a non-numeric, out-of-range, or empty value, with the NumError unwrapped and wrapped into this message.","triggerScenarios":"Passing `--publish published=abc`, `published=70000`, `published=-5`, or `published=` (empty). ParseUint fails, errors.As unwraps the cause, line 91 reports it.","commonSituations":"Typos, ports beyond 65535, negative values, empty env-var expansion, or accidentally putting the protocol in the published slot.","solutions":["Provide an integer 0–65535 for published: `--publish published=8080`.","Strip units/signs/whitespace from the value.","Pre-validate with `strconv.ParseUint(val, 10, 16)`.","If you don't need a fixed host port, omit published and let Swarm assign one."],"exampleFix":"// before\n--publish published=8080tcp,target=80\n// after\n--publish published=8080,target=80,protocol=tcp","handlingStrategy":"validation","validationCode":"// Validate the published (host) port as a uint16 before Set.\nif _, err := strconv.ParseUint(publishedVal, 10, 16); err != nil {\n    return fmt.Errorf(\"published port %q must be an integer 0-65535\", publishedVal)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Published port must be 0–65535, plain decimal.","Omit published to let Swarm assign a host port.","Keep the protocol out of the published slot.","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"}