docker/cli · error · invalidParameterErr

conflicting options: cannot specify both --ip and…

Error message

conflicting options: cannot specify both --ip and per-network IPv4 address

What it means

Returned by applyContainerOptions when both the global --ip flag (copts.ipv4Address) and a per-network IPv4 address inside the advanced --network notation (n.IPv4Address) are specified for the first network (opts.go:818-820). n.IPv4Address.IsValid() being true alongside a non-nil copts.ipv4Address triggers invalidParameter.

Solutions

  1. Use only the advanced per-network IP: --network=mynet:ipv4=172.20.0.5.
  2. Or use only the global --ip=172.20.0.5 and drop ipv4= from the --network value.
  3. For multiple networks, use the per-network form for each.

Example fix

// before
docker run --ip=172.20.0.5 --network=mynet:ipv4=172.20.0.6 myimage
// after
docker run --network=mynet:ipv4=172.20.0.5 myimage
Defensive patterns

Strategy: validation

Validate before calling

if n.IPv4Address.IsValid() && copts.ipv4Address != nil {
    return errors.New("cannot specify both --ip and per-network IPv4 address")
}

Prevention

When it happens

Trigger: Running `docker run --ip=172.20.0.5 --network=mynet:ipv4=172.20.0.6 ...` where the --network value carries an `ipv4=` option and the global --ip is also present. Applies to the first network only (i==0).

Common situations: Migrating to advanced multi-network notation but forgetting to remove the legacy --ip; compose configs that specify both per-network and a global IP; templating duplication.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/f15ac3d1496ac8bb. Report an issue: GitHub.

Appendix: source

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

		}
		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,
	// 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())

View on GitHub (pinned to 4f84911bfe)