{"id":"f0ff0a332a79a9ac","repo":"docker/cli","slug":"conflicting-options-cannot-specify-both-network","errorCode":null,"errorMessage":"conflicting options: cannot specify both --network-alias and per-network alias","messagePattern":"conflicting options: cannot specify both --network-alias and per-network alias","errorType":"validation","errorClass":"invalidParameter","httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":813,"sourceCode":"\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\nfunc applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOptions) error { //nolint:gocyclo\n\t// TODO should we error if _any_ advanced option is used? (i.e. forbid to combine advanced notation with the \"old\" flags (`--network-alias`, `--link`, `--ip`, `--ip6`)?\n\tif len(n.Aliases) > 0 && copts.aliases.Len() > 0 {\n\t\treturn invalidParameter(errors.New(\"conflicting options: cannot specify both --network-alias and per-network alias\"))\n\t}\n\tif len(n.Links) > 0 && copts.links.Len() > 0 {\n\t\treturn invalidParameter(errors.New(\"conflicting options: cannot specify both --link and per-network links\"))\n\t}\n\tif n.IPv4Address.IsValid() && copts.ipv4Address != nil {\n\t\treturn invalidParameter(errors.New(\"conflicting options: cannot specify both --ip and per-network IPv4 address\"))\n\t}\n\tif n.IPv6Address.IsValid() && copts.ipv6Address != nil {\n\t\treturn invalidParameter(errors.New(\"conflicting options: cannot specify both --ip6 and per-network IPv6 address\"))\n\t}\n\tif n.MacAddress != \"\" && copts.macAddress != \"\" {\n\t\treturn invalidParameter(errors.New(\"conflicting options: cannot specify both --mac-address and per-network MAC address\"))\n\t}\n\tif len(n.LinkLocalIPs) > 0 && copts.linkLocalIPs.Len() > 0 {\n\t\treturn invalidParameter(errors.New(\"conflicting options: cannot specify both --link-local-ip and per-network link-local IP addresses\"))\n\t}\n\tif copts.aliases.Len() > 0 {\n\t\tn.Aliases = make([]string, copts.aliases.Len())","sourceCodeStart":795,"sourceCodeEnd":831,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/opts.go#L795-L831","documentation":"Raised in applyContainerOptions (cli/command/container/opts.go:812) when a container run/create command supplies network aliases both via the top-level --network-alias flag and via the advanced per-network syntax (--network name=...,alias=...). The CLI cannot decide which set should win, so it refuses to merge them rather than silently preferring one.","triggerScenarios":"Running `docker run --network-alias foo --network mynet,alias=bar ...` (or docker create) so that copts.aliases is non-empty while the NetworkAttachmentOpts for a network also carries aliases; the check fires while backfilling legacy flags onto the first --network entry.","commonSituations":"Scripts or compose-to-CLI translations that mix the legacy flat flags with the newer advanced `--network name=net,alias=...` notation; copy-pasted commands upgraded to advanced syntax without removing the old flag.","solutions":["Remove --network-alias and put every alias in the advanced syntax: --network name=mynet,alias=foo,alias=bar","Or drop the per-network alias and use only --network-alias with a plain --network mynet","If attaching multiple networks, use per-network alias syntax exclusively, since --network-alias only applies to the first network"],"exampleFix":"// before\ndocker run --network-alias web --network name=appnet,alias=api nginx\n// after\ndocker run --network name=appnet,alias=api,alias=web nginx","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","network","flag-conflict","container"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}