{"record":{"id":"cad287813df756b0","repo":"docker/cli","slug":"invalid-publish-mode-value-s-must-be-either","errorCode":null,"errorMessage":"invalid publish mode value (%s): must be either '%s' or '%s'","messagePattern":"invalid publish mode value \\((.+?)\\): must be either '(.+?)' or '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/swarmopts/port.go","lineNumber":71,"sourceCode":"\t\t\t// TODO(thaJeztah): these options should not be case-insensitive.\n\t\t\tkey, val, ok := strings.Cut(strings.ToLower(field), \"=\")\n\t\t\tif !ok || key == \"\" {\n\t\t\t\treturn fmt.Errorf(\"invalid field: %s\", field)\n\t\t\t}\n\t\t\tswitch key {\n\t\t\tcase portOptProtocol:\n\t\t\t\tswitch proto := network.IPProtocol(val); proto {\n\t\t\t\tcase network.TCP, network.UDP, network.SCTP:\n\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","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/swarmopts/port.go#L53-L89","documentation":"Thrown by PortOpt.Set (port.go:71) when the `mode` field is neither 'ingress' nor 'host'. Swarm service port publish modes are limited to these two values; the switch over swarm.PortConfigPublishMode(val) matches only PortConfigPublishModeIngress and PortConfigPublishModeHost, so any other string hits the default case.","triggerScenarios":"Passing `--publish target=80,mode=bridge`, `mode=mesh`, `mode=global`, or a typo like `mode=ingres`. swarm.PortConfigPublishMode(val) yields a value not equal to either constant, firing line 71.","commonSituations":"Confusing swarm publish modes with Docker network drivers (bridge/host as a driver), typos, or assuming 'global' (a service mode) is a publish mode.","solutions":["Use mode=ingress (default, routing mesh) or mode=host (bypass mesh, host-native).","Double-check spelling: 'ingress' not 'ingres', 'host' not 'hosts'.","If unsure, omit the mode field to get the default (ingress).","Remember: these are publish modes, not network drivers."],"exampleFix":"// before\n--publish target=80,mode=bridge\n// after\n--publish target=80,mode=ingress   (or mode=host to bypass the routing mesh)","handlingStrategy":"validation","validationCode":"// Restrict publish mode to ingress/host.\nvar okMode = map[string]bool{\"ingress\": true, \"host\": true}\nif !okMode[strings.ToLower(modeVal)] {\n    return fmt.Errorf(\"mode %q must be ingress or host\", modeVal)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use mode=ingress (routing mesh) or mode=host (no mesh).","Omit mode to default to ingress.","Don't conflate publish modes with network drivers.","Spell 'ingress' fully."],"tags":["docker","swarm","port","validation","networking","publish-mode","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}