github.com/mheon/docker@v0.11.2-0.20150922122814-44f47903a831/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 switch mode := parts[0]; mode { 19 case "default", "bridge", "none", "host": 20 case "container": 21 if len(parts) < 2 || parts[1] == "" { 22 return fmt.Errorf("--net: invalid net mode: invalid container format container:<name|id>") 23 } 24 default: 25 return fmt.Errorf("invalid --net: %s", hc.NetworkMode) 26 } 27 28 if (hc.NetworkMode.IsHost() || hc.NetworkMode.IsContainer()) && c.Hostname != "" { 29 return ErrConflictNetworkHostname 30 } 31 32 if hc.NetworkMode.IsHost() && len(hc.Links) > 0 { 33 return ErrConflictHostNetworkAndLinks 34 } 35 36 if hc.NetworkMode.IsContainer() && len(hc.Links) > 0 { 37 return ErrConflictContainerNetworkAndLinks 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 }