docker/cli · error · invalidParameter

conflicting options: cannot specify both --mac-address and p

Error message

conflicting options: cannot specify both --mac-address and per-network MAC address

What it means

Raised in applyContainerOptions (opts.go:824) when a MAC address is set both with the top-level --mac-address flag and with mac-address= in the advanced per-network syntax. An endpoint has a single MAC, so the CLI refuses to guess which value to use.

Source

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

	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,
	// for the default bridge it defines a legacy-link.
	if container.NetworkMode(n.Target).IsUserDefined() && copts.links.Len() > 0 {
		n.Links = make([]string, copts.links.Len())
		copy(n.Links, copts.links.GetSlice())
	}
	if copts.ipv4Address != nil {
		if ipv4, ok := netip.AddrFromSlice(copts.ipv4Address.To4()); ok {
			n.IPv4Address = ipv4
		}

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Specify the MAC only per network: --network name=mynet,mac-address=02:42:ac:11:00:02
  2. Or use --mac-address with a plain --network mynet
  3. With multiple networks, use per-network mac-address= since the flat flag maps only to the first network

Example fix

// before
docker run --mac-address 02:42:ac:11:00:02 --network name=appnet,mac-address=02:42:ac:11:00:03 nginx
// after
docker run --network name=appnet,mac-address=02:42:ac:11:00:02 nginx

When it happens

Trigger: `docker run --mac-address 02:42:ac:11:00:02 --network name=mynet,mac-address=02:42:ac:11:00:03 ...` — n.MacAddress non-empty while copts.macAddress is also set.

Common situations: License- or DHCP-pinned MAC setups moving from single-network flags to multi-network advanced notation; tooling that always injects --mac-address.

Related errors


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