docker/cli · error · invalidParameterErr
conflicting options: cannot specify both --link and…
Error message
conflicting options: cannot specify both --link and per-network links
What it means
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.
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.
Example fix
// before docker run --link=redis --network=mynet:link=cache myimage // after docker run --network=mynet:link=cache myimage
Defensive patterns
Strategy: validation
Validate before calling
if len(n.Links) > 0 && copts.links.Len() > 0 {
return errors.New("cannot specify both --link and per-network links")
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: Migrating legacy --link usage into advanced --network notation without removing the old flags; compose templates that emit both link forms; assuming both are additive.
Related errors
- conflicting options: cannot attach both user-defined and…
- conflicting options: cannot specify both --network-alias…
- conflicting options: cannot specify both --ip and…
- conflicting options: cannot specify both --ip6 and…
- conflicting options: cannot specify both --mac-address and…
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/599beab51b945016.
Report an issue: GitHub.
Appendix: source
Thrown at cli/command/container/opts.go:816
if ep == nil || reflect.ValueOf(*ep).IsZero() {
continue
}
}
endpoints[n.Target] = ep
}
if hasUserDefined && hasNonUserDefined {
return nil, invalidParameter(errors.New("conflicting options: cannot attach both user-defined and non-user-defined network-modes"))
}
return endpoints, nil
}
func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOptions) error { //nolint:gocyclo
// 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`)?
if len(n.Aliases) > 0 && copts.aliases.Len() > 0 {
return invalidParameter(errors.New("conflicting options: cannot specify both --network-alias and per-network alias"))
}
if len(n.Links) > 0 && copts.links.Len() > 0 {
return invalidParameter(errors.New("conflicting options: cannot specify both --link and per-network links"))
}
if n.IPv4Address.IsValid() && copts.ipv4Address != nil {
return invalidParameter(errors.New("conflicting options: cannot specify both --ip and per-network IPv4 address"))
}
if n.IPv6Address.IsValid() && copts.ipv6Address != nil {
return invalidParameter(errors.New("conflicting options: cannot specify both --ip6 and per-network IPv6 address"))
}
if n.MacAddress != "" && copts.macAddress != "" {
return invalidParameter(errors.New("conflicting options: cannot specify both --mac-address and per-network MAC address"))
}
if len(n.LinkLocalIPs) > 0 && copts.linkLocalIPs.Len() > 0 {
return invalidParameter(errors.New("conflicting options: cannot specify both --link-local-ip and per-network link-local IP addresses"))
}
if copts.aliases.Len() > 0 {
n.Aliases = make([]string, copts.aliases.Len())
copy(n.Aliases, copts.aliases.GetSlice())
}
// For a user-defined network, "--link" is an endpoint option, it creates an alias. But,View on GitHub (pinned to 4f84911bfe)