docker/cli · error · invalidParameter
conflicting options: cannot specify both --link and per-netw
Error message
conflicting options: cannot specify both --link and per-network links
What it means
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.
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 e9452d6e78)
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
Example fix
// before docker run --link db --network name=appnet,link=cache nginx // after docker run --network name=appnet,link=db,link=cache nginx
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- conflicting options: cannot specify both --network-alias and
- conflicting options: cannot specify both --ip and per-networ
- conflicting options: cannot specify both --ip6 and per-netwo
- conflicting options: cannot specify both --mac-address and p
- conflicting options: cannot specify both --link-local-ip and
AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01).
Data as JSON: /data/errors/599beab51b945016.json.
Report an issue: GitHub.