{"id":"f15ac3d1496ac8bb","repo":"docker/cli","slug":"conflicting-options-cannot-specify-both-ip-and","errorCode":null,"errorMessage":"conflicting options: cannot specify both --ip and per-network IPv4 address","messagePattern":"conflicting options: cannot specify both --ip and per-network IPv4 address","errorType":"validation","errorClass":"invalidParameter","httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":819,"sourceCode":"\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())\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())","sourceCodeStart":801,"sourceCodeEnd":837,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/opts.go#L801-L837","documentation":"Raised in applyContainerOptions (opts.go:818) when a static IPv4 address is specified both via --ip and via the advanced per-network syntax (--network name=...,ip=...). An endpoint can only have one IPv4 IPAM address, so the CLI rejects the ambiguous combination.","triggerScenarios":"`docker run --ip 172.20.0.5 --network name=mynet,ip=172.20.0.6 ...` — n.IPv4Address is valid from the advanced option while copts.ipv4Address is also set.","commonSituations":"Automation that appends --ip globally while templates already embed ip= in the --network option; migrating single-network commands to multi-network advanced syntax without removing the old flag.","solutions":["Specify the address only in the advanced syntax: --network name=mynet,ip=172.20.0.5","Or remove the per-network ip= and use --ip with a plain --network mynet","Ensure the chosen address falls within the network's subnet (the network must have a user-configured subnet for static IPs)"],"exampleFix":"// before\ndocker run --ip 172.20.0.5 --network name=appnet,ip=172.20.0.6 nginx\n// after\ndocker run --network name=appnet,ip=172.20.0.5 nginx","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","network","ipv4","static-ip","flag-conflict"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}