{"record":{"id":"b87230a2ca7882b1","repo":"docker/cli","slug":"network-q-is-specified-multiple-times","errorCode":null,"errorMessage":"network %q is specified multiple times","messagePattern":"network %q is specified multiple times","errorType":"validation","errorClass":"invalidParameterErr","httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":791,"sourceCode":"\t\t} else {\n\t\t\thasNonUserDefined = true\n\t\t}\n\t\tif i == 0 {\n\t\t\t// The first network corresponds with what was previously the \"only\"\n\t\t\t// network, and what would be used when using the non-advanced syntax\n\t\t\t// `--network-alias`, `--link`, `--ip`, `--ip6`, and `--link-local-ip`\n\t\t\t// are set on this network, to preserve backward compatibility with\n\t\t\t// the non-advanced notation\n\t\t\tif err := applyContainerOptions(&n, copts); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\t\tep, err := parseNetworkAttachmentOpt(n)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif _, ok := endpoints[n.Target]; ok {\n\t\t\treturn nil, invalidParameter(fmt.Errorf(\"network %q is specified multiple times\", n.Target))\n\t\t}\n\n\t\t// For backward compatibility: if no custom options are provided for the network,\n\t\t// and only a single network is specified, omit the endpoint-configuration\n\t\t// on the client (the daemon will still create it when creating the container)\n\t\tif i == 0 && len(copts.netMode.Value()) == 1 {\n\t\t\tif ep == nil || reflect.ValueOf(*ep).IsZero() {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t\tendpoints[n.Target] = ep\n\t}\n\tif hasUserDefined && hasNonUserDefined {\n\t\treturn nil, invalidParameter(errors.New(\"conflicting options: cannot attach both user-defined and non-user-defined network-modes\"))\n\t}\n\treturn endpoints, nil\n}\n","sourceCodeStart":773,"sourceCodeEnd":809,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/opts.go#L773-L809","documentation":"Returned in opts.go:791 when the same network target name appears more than once in the --network arguments. Each endpoint target must be unique; duplicates are rejected as an invalid parameter so that the daemon receives an unambiguous endpoint set.","triggerScenarios":"`docker run --network mynet --network mynet ...` (same target twice), or a composable setup that appends the same network more than once.","commonSituations":"A wrapper script or compose translation that repeats the primary network, or merging multiple --network flags that resolve to the same name.","solutions":["List each network only once.","If you need multiple attachments to the same network, that is not supported; use distinct networks.","De-duplicate network names before building the command line."],"exampleFix":"# before\ndocker run --network appnet --network appnet alpine\n\n# after\ndocker run --network appnet --network sidecarnet alpine","handlingStrategy":"validation","validationCode":"func dedupeNetworks(specs []string) ([]string, error) {\n    seen := map[string]bool{}\n    var out []string\n    for _, s := range specs {\n        name := strings.SplitN(s, \":\", 2)[0]\n        if seen[name] { return nil, fmt.Errorf(\"network %q duplicated\", name) }\n        seen[name] = true; out = append(out, s)\n    }\n    return out, nil\n}","typeGuard":null,"tryCatchPattern":"// Duplicate detection is deterministic; dedupe before invoking.\nif specs, err := dedupeNetworks(specs); err != nil { /* report */ } else { use(specs) }","preventionTips":["De-duplicate --network targets in command builders.\nUse distinct networks when multiple attachments are needed.\nValidate compose/network lists for repeats."],"tags":["container","network","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"}