docker/cli · error · invalidParameter

conflicting options: cannot specify both --network-alias and

Error message

conflicting options: cannot specify both --network-alias and per-network alias

What it means

Raised in applyContainerOptions (cli/command/container/opts.go:812) when a container run/create command supplies network aliases both via the top-level --network-alias flag and via the advanced per-network syntax (--network name=...,alias=...). The CLI cannot decide which set should win, so it refuses to merge them rather than silently preferring one.

Source

Thrown at cli/command/container/opts.go:813

		// and only a single network is specified, omit the endpoint-configuration
		// on the client (the daemon will still create it when creating the container)
		if i == 0 && len(copts.netMode.Value()) == 1 {
			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())

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Remove --network-alias and put every alias in the advanced syntax: --network name=mynet,alias=foo,alias=bar
  2. Or drop the per-network alias and use only --network-alias with a plain --network mynet
  3. If attaching multiple networks, use per-network alias syntax exclusively, since --network-alias only applies to the first network

Example fix

// before
docker run --network-alias web --network name=appnet,alias=api nginx
// after
docker run --network name=appnet,alias=api,alias=web nginx

When it happens

Trigger: Running `docker run --network-alias foo --network mynet,alias=bar ...` (or docker create) so that copts.aliases is non-empty while the NetworkAttachmentOpts for a network also carries aliases; the check fires while backfilling legacy flags onto the first --network entry.

Common situations: Scripts or compose-to-CLI translations that mix the legacy flat flags with the newer advanced `--network name=net,alias=...` notation; copy-pasted commands upgraded to advanced syntax without removing the old flag.

Related errors


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/f0ff0a332a79a9ac.json. Report an issue: GitHub.