mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
2ab94e11a2
* Moving Network Remote APIs out of experimental * --net can now accept user created networks using network drivers/plugins * Removed the experimental services concept and --default-network option * Neccessary backend changes to accomodate multiple networks per container * Integration Tests Signed-off-by: David Calavera <david.calavera@gmail.com> Signed-off-by: Madhu Venugopal <madhu@docker.com>
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
// +build !windows
|
|
|
|
package runconfig
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// ValidateNetMode ensures that the various combinations of requested
|
|
// network settings are valid.
|
|
func ValidateNetMode(c *Config, hc *HostConfig) error {
|
|
// We may not be passed a host config, such as in the case of docker commit
|
|
if hc == nil {
|
|
return nil
|
|
}
|
|
parts := strings.Split(string(hc.NetworkMode), ":")
|
|
if parts[0] == "container" {
|
|
if len(parts) < 2 || parts[1] == "" {
|
|
return fmt.Errorf("--net: invalid net mode: invalid container format container:<name|id>")
|
|
}
|
|
}
|
|
|
|
if (hc.NetworkMode.IsHost() || hc.NetworkMode.IsContainer()) && c.Hostname != "" {
|
|
return ErrConflictNetworkHostname
|
|
}
|
|
|
|
if hc.NetworkMode.IsHost() && len(hc.Links) > 0 {
|
|
return ErrConflictHostNetworkAndLinks
|
|
}
|
|
|
|
if hc.NetworkMode.IsContainer() && len(hc.Links) > 0 {
|
|
return ErrConflictContainerNetworkAndLinks
|
|
}
|
|
|
|
if hc.NetworkMode.IsUserDefined() && len(hc.Links) > 0 {
|
|
return ErrConflictUserDefinedNetworkAndLinks
|
|
}
|
|
|
|
if (hc.NetworkMode.IsHost() || hc.NetworkMode.IsContainer()) && len(hc.DNS) > 0 {
|
|
return ErrConflictNetworkAndDNS
|
|
}
|
|
|
|
if (hc.NetworkMode.IsContainer() || hc.NetworkMode.IsHost()) && len(hc.ExtraHosts) > 0 {
|
|
return ErrConflictNetworkHosts
|
|
}
|
|
|
|
if (hc.NetworkMode.IsContainer() || hc.NetworkMode.IsHost()) && c.MacAddress != "" {
|
|
return ErrConflictContainerNetworkAndMac
|
|
}
|
|
|
|
if hc.NetworkMode.IsContainer() && (len(hc.PortBindings) > 0 || hc.PublishAllPorts == true) {
|
|
return ErrConflictNetworkPublishPorts
|
|
}
|
|
|
|
if hc.NetworkMode.IsContainer() && len(c.ExposedPorts) > 0 {
|
|
return ErrConflictNetworkExposePorts
|
|
}
|
|
return nil
|
|
}
|