2015-06-23 13:13:42 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-09-18 21:21:57 -04:00
|
|
|
"runtime"
|
2015-06-23 13:13:42 -04:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-07-09 18:12:36 -04:00
|
|
|
// 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), ":")
|
2015-09-25 06:19:17 -04:00
|
|
|
if parts[0] == "container" {
|
2015-06-23 13:13:42 -04:00
|
|
|
if len(parts) < 2 || parts[1] == "" {
|
2015-07-09 18:12:36 -04:00
|
|
|
return fmt.Errorf("--net: invalid net mode: invalid container format container:<name|id>")
|
2015-06-23 13:13:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 18:12:36 -04:00
|
|
|
if (hc.NetworkMode.IsHost() || hc.NetworkMode.IsContainer()) && c.Hostname != "" {
|
2015-06-23 13:13:42 -04:00
|
|
|
return ErrConflictNetworkHostname
|
|
|
|
}
|
|
|
|
|
2015-07-09 18:12:36 -04:00
|
|
|
if hc.NetworkMode.IsHost() && len(hc.Links) > 0 {
|
2015-06-23 13:13:42 -04:00
|
|
|
return ErrConflictHostNetworkAndLinks
|
|
|
|
}
|
|
|
|
|
2015-07-09 18:12:36 -04:00
|
|
|
if hc.NetworkMode.IsContainer() && len(hc.Links) > 0 {
|
2015-06-23 13:13:42 -04:00
|
|
|
return ErrConflictContainerNetworkAndLinks
|
|
|
|
}
|
|
|
|
|
2015-09-25 06:19:17 -04:00
|
|
|
if hc.NetworkMode.IsUserDefined() && len(hc.Links) > 0 {
|
|
|
|
return ErrConflictUserDefinedNetworkAndLinks
|
|
|
|
}
|
|
|
|
|
2015-07-09 18:12:36 -04:00
|
|
|
if (hc.NetworkMode.IsHost() || hc.NetworkMode.IsContainer()) && len(hc.DNS) > 0 {
|
2015-07-25 05:11:45 -04:00
|
|
|
return ErrConflictNetworkAndDNS
|
2015-06-23 13:13:42 -04:00
|
|
|
}
|
|
|
|
|
2015-07-09 18:12:36 -04:00
|
|
|
if (hc.NetworkMode.IsContainer() || hc.NetworkMode.IsHost()) && len(hc.ExtraHosts) > 0 {
|
2015-06-23 13:13:42 -04:00
|
|
|
return ErrConflictNetworkHosts
|
|
|
|
}
|
|
|
|
|
2015-07-09 18:12:36 -04:00
|
|
|
if (hc.NetworkMode.IsContainer() || hc.NetworkMode.IsHost()) && c.MacAddress != "" {
|
2015-06-23 13:13:42 -04:00
|
|
|
return ErrConflictContainerNetworkAndMac
|
|
|
|
}
|
|
|
|
|
2015-07-09 18:12:36 -04:00
|
|
|
if hc.NetworkMode.IsContainer() && (len(hc.PortBindings) > 0 || hc.PublishAllPorts == true) {
|
2015-06-23 13:13:42 -04:00
|
|
|
return ErrConflictNetworkPublishPorts
|
|
|
|
}
|
|
|
|
|
2015-07-09 18:12:36 -04:00
|
|
|
if hc.NetworkMode.IsContainer() && len(c.ExposedPorts) > 0 {
|
2015-06-23 13:13:42 -04:00
|
|
|
return ErrConflictNetworkExposePorts
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2015-09-18 21:21:57 -04:00
|
|
|
|
|
|
|
// ValidateIsolationLevel performs platform specific validation of the
|
|
|
|
// isolation level in the hostconfig structure. Linux only supports "default"
|
|
|
|
// which is LXC container isolation
|
|
|
|
func ValidateIsolationLevel(hc *HostConfig) error {
|
|
|
|
// We may not be passed a host config, such as in the case of docker commit
|
|
|
|
if hc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if !hc.Isolation.IsValid() {
|
|
|
|
return fmt.Errorf("invalid --isolation: %q - %s only supports 'default'", hc.Isolation, runtime.GOOS)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|