{"record":{"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":"invalidParameterErr","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/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/opts.go#L798-L834","documentation":"Returned by applyContainerOptions when both the global --link flag (copts.links) and per-network links inside the advanced --network notation (n.Links) are specified for the first network (opts.go:815-817). Links are endpoint-scoped on user-defined networks, so specifying both sources is ambiguous and rejected as invalidParameter.","triggerScenarios":"Running `docker run --link=redis --network=mynet:link=cache ...` where the --network value carries a `link=` option and the global --link is also present. Applies to the first network only (i==0).","commonSituations":"Migrating legacy --link usage into advanced --network notation without removing the old flags; compose templates that emit both link forms; assuming both are additive.","solutions":["Use only the advanced per-network link: --network=mynet:link=cache.","Or use only the global --link=cache and drop the link= from the --network value.","Modernize away from --link entirely using user-defined DNS where possible."],"exampleFix":"// before\ndocker run --link=redis --network=mynet:link=cache myimage\n// after\ndocker run --network=mynet:link=cache myimage","handlingStrategy":"validation","validationCode":"if len(n.Links) > 0 && copts.links.Len() > 0 {\n    return errors.New(\"cannot specify both --link and per-network links\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one link notation; prefer per-network link= in advanced form.","Where possible, replace --link with user-defined network DNS.","Audit migrated compose files for residual global --link flags."],"tags":["docker-cli","network","links","conflicting-options","validation","container-create"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}