{"id":"f5817d00af83882d","repo":"docker/cli","slug":"conflicting-options-cannot-specify-both-mac-add","errorCode":null,"errorMessage":"conflicting options: cannot specify both --mac-address and per-network MAC address","messagePattern":"conflicting options: cannot specify both --mac-address and per-network MAC address","errorType":"validation","errorClass":"invalidParameter","httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":825,"sourceCode":"\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())\n\t\tcopy(n.Aliases, copts.aliases.GetSlice())\n\t}\n\t// For a user-defined network, \"--link\" is an endpoint option, it creates an alias. But,\n\t// for the default bridge it defines a legacy-link.\n\tif container.NetworkMode(n.Target).IsUserDefined() && copts.links.Len() > 0 {\n\t\tn.Links = make([]string, copts.links.Len())\n\t\tcopy(n.Links, copts.links.GetSlice())\n\t}\n\tif copts.ipv4Address != nil {\n\t\tif ipv4, ok := netip.AddrFromSlice(copts.ipv4Address.To4()); ok {\n\t\t\tn.IPv4Address = ipv4\n\t\t}","sourceCodeStart":807,"sourceCodeEnd":843,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/opts.go#L807-L843","documentation":"Raised in applyContainerOptions (opts.go:824) when a MAC address is set both with the top-level --mac-address flag and with mac-address= in the advanced per-network syntax. An endpoint has a single MAC, so the CLI refuses to guess which value to use.","triggerScenarios":"`docker run --mac-address 02:42:ac:11:00:02 --network name=mynet,mac-address=02:42:ac:11:00:03 ...` — n.MacAddress non-empty while copts.macAddress is also set.","commonSituations":"License- or DHCP-pinned MAC setups moving from single-network flags to multi-network advanced notation; tooling that always injects --mac-address.","solutions":["Specify the MAC only per network: --network name=mynet,mac-address=02:42:ac:11:00:02","Or use --mac-address with a plain --network mynet","With multiple networks, use per-network mac-address= since the flat flag maps only to the first network"],"exampleFix":"// before\ndocker run --mac-address 02:42:ac:11:00:02 --network name=appnet,mac-address=02:42:ac:11:00:03 nginx\n// after\ndocker run --network name=appnet,mac-address=02:42:ac:11:00:02 nginx","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","network","mac-address","flag-conflict"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}