{"id":"599beab51b945016","repo":"docker/cli","slug":"conflicting-options-cannot-specify-both-link-an","errorCode":null,"errorMessage":"conflicting options: cannot specify both --link and per-network links","messagePattern":"conflicting options: cannot specify both --link and per-network links","errorType":"validation","errorClass":"invalidParameter","httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":816,"sourceCode":"\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())\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,","sourceCodeStart":798,"sourceCodeEnd":834,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/opts.go#L798-L834","documentation":"Raised in applyContainerOptions (opts.go:815) when container links are given both with the top-level --link flag and inside the advanced per-network syntax (--network name=...,link=...). The two notations target the same endpoint field, so combining them is ambiguous and rejected.","triggerScenarios":"`docker run --link db:db --network name=mynet,link=other ...` — copts.links non-empty while the parsed NetworkAttachmentOpts also has Links; validated when the legacy flags are applied to the first --network entry.","commonSituations":"Legacy scripts using --link (a deprecated bridge-network feature) being migrated to user-defined networks with advanced --network options, leaving the old flag in place.","solutions":["Use only the per-network form: --network name=mynet,link=db:db and drop --link","Or keep --link and use a plain --network mynet without per-network links","Prefer replacing links entirely with network aliases and DNS on a user-defined network, since --link is legacy"],"exampleFix":"// before\ndocker run --link db --network name=appnet,link=cache nginx\n// after\ndocker run --network name=appnet,link=db,link=cache nginx","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","network","links","flag-conflict"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}