github.com/yamamoto-febc/docker@v1.9.0/runconfig/parse_unix.go (about) 1 // +build !windows 2 3 package runconfig 4 5 import ( 6 "fmt" 7 "strings" 8 ) 9 10 // ValidateNetMode ensures that the various combinations of requested 11 // network settings are valid. 12 func ValidateNetMode(c *Config, hc *HostConfig) error { 13 // We may not be passed a host config, such as in the case of docker commit 14 if hc == nil { 15 return nil 16 } 17 parts := strings.Split(string(hc.NetworkMode), ":") 18 if parts[0] == "container" { 19 if len(parts) < 2 || parts[1] == "" { 20 return fmt.Errorf("--net: invalid net mode: invalid container format container:<name|id>") 21 } 22 } 23 24 if (hc.NetworkMode.IsHost() || hc.NetworkMode.IsContainer()) && c.Hostname != "" { 25 return ErrConflictNetworkHostname 26 } 27 28 if hc.NetworkMode.IsHost() && len(hc.Links) > 0 { 29 return ErrConflictHostNetworkAndLinks 30 } 31 32 if hc.NetworkMode.IsContainer() && len(hc.Links) > 0 { 33 return ErrConflictContainerNetworkAndLinks 34 } 35 36 if hc.NetworkMode.IsUserDefined() && len(hc.Links) > 0 { 37 return ErrConflictUserDefinedNetworkAndLinks 38 } 39 40 if (hc.NetworkMode.IsHost() || hc.NetworkMode.IsContainer()) && len(hc.DNS) > 0 { 41 return ErrConflictNetworkAndDNS 42 } 43 44 if (hc.NetworkMode.IsContainer() || hc.NetworkMode.IsHost()) && len(hc.ExtraHosts) > 0 { 45 return ErrConflictNetworkHosts 46 } 47 48 if (hc.NetworkMode.IsContainer() || hc.NetworkMode.IsHost()) && c.MacAddress != "" { 49 return ErrConflictContainerNetworkAndMac 50 } 51 52 if hc.NetworkMode.IsContainer() && (len(hc.PortBindings) > 0 || hc.PublishAllPorts == true) { 53 return ErrConflictNetworkPublishPorts 54 } 55 56 if hc.NetworkMode.IsContainer() && len(c.ExposedPorts) > 0 { 57 return ErrConflictNetworkExposePorts 58 } 59 return nil 60 }