{"record":{"id":"dc09cffdc471780d","repo":"docker/cli","slug":"invalid-field-key-s","errorCode":null,"errorMessage":"invalid field key: %s","messagePattern":"invalid field key: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/swarmopts/port.go","lineNumber":96,"sourceCode":"\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})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfor _, portBindings := range portBindingMap {\n\t\t\tfor _, portBinding := range portBindings {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/swarmopts/port.go#L78-L114","documentation":"Thrown by PortOpt.Set (port.go:96) when a field key in long syntax is not one of target, published, protocol, mode. Any unrecognized key (typo or unsupported) reaches the switch default and is reported. Note the key is already lowercased at line 54, so case is not the issue.","triggerScenarios":"Passing `--publish port=80` (should be `target=80`), `host=8080` (should be `published`), `ip=127.0.0.1`, or any invented field. The switch at line 58 has no matching case, so line 96 fires with the offending key.","commonSituations":"Using generic names like 'port'/'host' instead of 'target'/'published', trying to bind an IP (not supported in long syntax — use short syntax or it's rejected), or version skew.","solutions":["Use only the supported keys: target, published, protocol, mode.","For IP binding, note hostip is unsupported for swarm services (see line 116).","Verify field names against `docker service create --help` for your CLI version.","Check for typos; keys are case-insensitive but name-strict."],"exampleFix":"// before\n--publish port=80,host=8080\n// after\n--publish target=80,published=8080","handlingStrategy":"validation","validationCode":"// Allowlist long-syntax publish keys.\nvar portKeys = map[string]bool{\"target\": true, \"published\": true, \"protocol\": true, \"mode\": true}\nfor _, f := range strings.Split(pubVal, \",\") {\n    k, _, _ := strings.Cut(strings.ToLower(strings.TrimSpace(f)), \"=\")\n    if !portKeys[k] { return fmt.Errorf(\"unknown publish key %q\", k) }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use target (not 'port') and published (not 'host').","IP binding is unsupported in swarm long syntax (and hostip in short).","Verify keys against your CLI version's help.","Treat unknown-key errors as a spec/version mismatch."],"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"}