github.com/torfuzx/docker@v1.8.1/runconfig/parse_unix.go (about) 1 // +build !windows 2 3 package runconfig 4 5 import ( 6 "fmt" 7 "strings" 8 ) 9 10 func parseNetMode(netMode string) (NetworkMode, error) { 11 parts := strings.Split(netMode, ":") 12 switch mode := parts[0]; mode { 13 case "default", "bridge", "none", "host": 14 case "container": 15 if len(parts) < 2 || parts[1] == "" { 16 return "", fmt.Errorf("invalid container format container:<name|id>") 17 } 18 default: 19 return "", fmt.Errorf("invalid --net: %s", netMode) 20 } 21 return NetworkMode(netMode), nil 22 } 23 24 func validateNetMode(vals *validateNM) error { 25 26 if (vals.netMode.IsHost() || vals.netMode.IsContainer()) && *vals.flHostname != "" { 27 return ErrConflictNetworkHostname 28 } 29 30 if vals.netMode.IsHost() && vals.flLinks.Len() > 0 { 31 return ErrConflictHostNetworkAndLinks 32 } 33 34 if vals.netMode.IsContainer() && vals.flLinks.Len() > 0 { 35 return ErrConflictContainerNetworkAndLinks 36 } 37 38 if (vals.netMode.IsHost() || vals.netMode.IsContainer()) && vals.flDns.Len() > 0 { 39 return ErrConflictNetworkAndDns 40 } 41 42 if (vals.netMode.IsContainer() || vals.netMode.IsHost()) && vals.flExtraHosts.Len() > 0 { 43 return ErrConflictNetworkHosts 44 } 45 46 if (vals.netMode.IsContainer() || vals.netMode.IsHost()) && *vals.flMacAddress != "" { 47 return ErrConflictContainerNetworkAndMac 48 } 49 50 if vals.netMode.IsContainer() && (vals.flPublish.Len() > 0 || *vals.flPublishAll == true) { 51 return ErrConflictNetworkPublishPorts 52 } 53 54 if vals.netMode.IsContainer() && vals.flExpose.Len() > 0 { 55 return ErrConflictNetworkExposePorts 56 } 57 return nil 58 }