{"id":"239d347e9b45bddc","repo":"docker/cli","slug":"conflicting-options-cannot-attach-both-user-defin","errorCode":null,"errorMessage":"conflicting options: cannot attach both user-defined and non-user-defined network-modes","messagePattern":"conflicting options: cannot attach both user-defined and non-user-defined network-modes","errorType":"validation","errorClass":"invalidParameter","httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":805,"sourceCode":"\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\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}","sourceCodeStart":787,"sourceCodeEnd":823,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/opts.go#L787-L823","documentation":"parseNetworkOpts iterates every --network attachment and classifies each as user-defined (a named custom network) or non-user-defined (built-in modes like host, none, bridge, or container:<id>); if both classes appear it returns this invalid-parameter error (opts.go:770-806). Built-in modes define the container's whole network sandbox, so they cannot coexist with attachments to additional user-defined networks.","triggerScenarios":"Passing --network more than once mixing categories, e.g. `docker run --network host --network mynet image`, `--network=container:web --network=backend`, or `--network none --network bridge` combined with a custom network. Multiple user-defined networks together are accepted by the CLI (though older daemons may reject >1 at create).","commonSituations":"Trying to give a host-networked container access to a custom bridge network too; compose-style multi-network thinking applied to docker run with one of the networks being `host`; scripts appending a default `--network host` while the user adds their own network.","solutions":["Pick one category: either a single built-in mode (host/none/container:<id>) or one-or-more user-defined networks","To reach services on a user-defined network, drop --network host and attach only to the custom network, publishing ports as needed","If a container truly needs another network later, use `docker network connect <net> <container>` after creation with a compatible mode"],"exampleFix":"# before\ndocker run --network host --network mynet myimage\n# after\ndocker run --network mynet -p 8080:8080 myimage","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","network","conflicting-options","container-create"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}