api: ContainerCreate: clean up BC conditions
- First commit is related to https://github.com/moby/moby/pull/45905 ;
- Supersedes / Closes https://github.com/moby/moby/pull/42852 ;

**- What I did**

In `postContainersCreate`:

1. Init `hostConfig` and `networkingConfig` when they're nil ;
2. Return an error when `config` is nil ;
3. Remove repetitive nil checks on `config`, `hostConfig` and `networkingConfig` ;
4. Re-organize BC-related conditions ;

**- How to verify it**

CI is green.

**- A picture of a cute animal (not mandatory but encouraged)**

![](https://a-z-animals.com/media/butterfly-fish-1024x535.jpg)

runconfig/errors.go
package runconfig // import "github.com/docker/docker/runconfig"

const (
	// ErrConflictContainerNetworkAndLinks conflict between --net=container and links
	ErrConflictContainerNetworkAndLinks validationError = "conflicting options: container type network can't be used with links. This would result in undefined behavior"
	// ErrConflictSharedNetwork conflict between private and other networks
	ErrConflictSharedNetwork validationError = "container sharing network namespace with another container or host cannot be connected to any other network"
	// ErrConflictHostNetwork conflict from being disconnected from host network or connected to host network.
	ErrConflictHostNetwork validationError = "container cannot be disconnected from host network or connected to host network"
	// ErrConflictNoNetwork conflict between private and other networks
	ErrConflictNoNetwork validationError = "container cannot be connected to multiple networks with one of the networks in private (none) mode"
	// ErrConflictNetworkAndDNS conflict between --dns and the network mode
	ErrConflictNetworkAndDNS validationError = "conflicting options: dns and the network mode"
	// ErrConflictNetworkHostname conflict between the hostname and the network mode
	ErrConflictNetworkHostname validationError = "conflicting options: hostname and the network mode"
	// ErrConflictHostNetworkAndLinks conflict between --net=host and links
	ErrConflictHostNetworkAndLinks validationError = "conflicting options: host type networking can't be used with links. This would result in undefined behavior"
	// ErrConflictContainerNetworkAndMac conflict between the mac address and the network mode
	ErrConflictContainerNetworkAndMac validationError = "conflicting options: mac-address and the network mode"
	// ErrConflictNetworkHosts conflict between add-host and the network mode
	ErrConflictNetworkHosts validationError = "conflicting options: custom host-to-IP mapping and the network mode"
	// ErrConflictNetworkPublishPorts conflict between the publish options and the network mode
	ErrConflictNetworkPublishPorts validationError = "conflicting options: port publishing and the container type network mode"
	// ErrConflictNetworkExposePorts conflict between the expose option and the network mode
	ErrConflictNetworkExposePorts validationError = "conflicting options: port exposing and the container type network mode"
	// ErrUnsupportedNetworkAndIP conflict between network mode and requested ip address
	ErrUnsupportedNetworkAndIP validationError = "user specified IP address is supported on user defined networks only"
	// ErrUnsupportedNetworkNoSubnetAndIP conflict between network with no configured subnet and requested ip address
	ErrUnsupportedNetworkNoSubnetAndIP validationError = "user specified IP address is supported only when connecting to networks with user configured subnets"
	// ErrUnsupportedNetworkAndAlias conflict between network mode and alias
	ErrUnsupportedNetworkAndAlias validationError = "network-scoped alias is supported only for containers in user defined networks"
	// ErrConflictUTSHostname conflict between the hostname and the UTS mode
	ErrConflictUTSHostname validationError = "conflicting options: hostname and the UTS mode"
)

type validationError string

func (e validationError) Error() string {
	return string(e)
}

func (e validationError) InvalidParameter() {}

type invalidJSONError struct {
	Err error
}

func (e invalidJSONError) Error() string {
	return "invalid JSON: " + e.Err.Error()
}

func (e invalidJSONError) Unwrap() error {
	return e.Err
}

func (e invalidJSONError) InvalidParameter() {}

package runconfig // import "github.com/docker/docker/runconfig"

const (
	// ErrConflictContainerNetworkAndLinks conflict between --net=container and links
	ErrConflictContainerNetworkAndLinks validationError = "conflicting options: container type network can't be used with links. This would result in undefined behavior"
	// ErrConflictSharedNetwork conflict between private and other networks
	ErrConflictSharedNetwork validationError = "container sharing network namespace with another container or host cannot be connected to any other network"
	// ErrConflictHostNetwork conflict from being disconnected from host network or connected to host network.
	ErrConflictHostNetwork validationError = "container cannot be disconnected from host network or connected to host network"
	// ErrConflictNoNetwork conflict between private and other networks
	ErrConflictNoNetwork validationError = "container cannot be connected to multiple networks with one of the networks in private (none) mode"
	// ErrConflictNetworkAndDNS conflict between --dns and the network mode
	ErrConflictNetworkAndDNS validationError = "conflicting options: dns and the network mode"
	// ErrConflictNetworkHostname conflict between the hostname and the network mode
	ErrConflictNetworkHostname validationError = "conflicting options: hostname and the network mode"
	// ErrConflictHostNetworkAndLinks conflict between --net=host and links
	ErrConflictHostNetworkAndLinks validationError = "conflicting options: host type networking can't be used with links. This would result in undefined behavior"
	// ErrConflictContainerNetworkAndMac conflict between the mac address and the network mode
	ErrConflictContainerNetworkAndMac validationError = "conflicting options: mac-address and the network mode"
	// ErrConflictNetworkHosts conflict between add-host and the network mode
	ErrConflictNetworkHosts validationError = "conflicting options: custom host-to-IP mapping and the network mode"
	// ErrConflictNetworkPublishPorts conflict between the publish options and the network mode
	ErrConflictNetworkPublishPorts validationError = "conflicting options: port publishing and the container type network mode"
	// ErrConflictNetworkExposePorts conflict between the expose option and the network mode
	ErrConflictNetworkExposePorts validationError = "conflicting options: port exposing and the container type network mode"
	// ErrUnsupportedNetworkAndIP conflict between network mode and requested ip address
	ErrUnsupportedNetworkAndIP validationError = "user specified IP address is supported on user defined networks only"
	// ErrUnsupportedNetworkNoSubnetAndIP conflict between network with no configured subnet and requested ip address
	ErrUnsupportedNetworkNoSubnetAndIP validationError = "user specified IP address is supported only when connecting to networks with user configured subnets"
	// ErrUnsupportedNetworkAndAlias conflict between network mode and alias
	ErrUnsupportedNetworkAndAlias validationError = "network-scoped alias is supported only for containers in user defined networks"
	// ErrConflictUTSHostname conflict between the hostname and the UTS mode
	ErrConflictUTSHostname validationError = "conflicting options: hostname and the UTS mode"
	// ErrEmptyConfig when container config is nil
	ErrEmptyConfig validationError = "config cannot be empty in order to create a container"
)

type validationError string

func (e validationError) Error() string {
	return string(e)
}

func (e validationError) InvalidParameter() {}

type invalidJSONError struct {
	Err error
}

func (e invalidJSONError) Error() string {
	return "invalid JSON: " + e.Err.Error()
}

func (e invalidJSONError) Unwrap() error {
	return e.Err
}

func (e invalidJSONError) InvalidParameter() {}

At least not the CLI. Is that enough to consider fixing the capitalization?