2016-03-25 23:38:00 +00:00
|
|
|
// +build !windows,!solaris
|
2015-06-23 17:13:42 +00:00
|
|
|
|
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
2015-11-01 01:49:14 +00:00
|
|
|
"fmt"
|
|
|
|
"runtime"
|
2015-06-23 17:13:42 +00:00
|
|
|
"strings"
|
|
|
|
|
2016-01-05 00:05:26 +00:00
|
|
|
"github.com/docker/engine-api/types/container"
|
2015-12-18 18:36:17 +00:00
|
|
|
)
|
2015-06-23 17:13:42 +00:00
|
|
|
|
2015-07-25 09:11:45 +00:00
|
|
|
// DefaultDaemonNetworkMode returns the default network stack the daemon should
|
|
|
|
// use.
|
2015-12-18 18:36:17 +00:00
|
|
|
func DefaultDaemonNetworkMode() container.NetworkMode {
|
|
|
|
return container.NetworkMode("bridge")
|
2015-09-25 10:19:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-25 23:09:54 +00:00
|
|
|
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
|
|
|
|
func IsPreDefinedNetwork(network string) bool {
|
2015-12-18 18:36:17 +00:00
|
|
|
n := container.NetworkMode(network)
|
2016-01-19 02:12:02 +00:00
|
|
|
return n.IsBridge() || n.IsHost() || n.IsNone() || n.IsDefault()
|
2015-10-25 23:09:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-01 01:49:14 +00:00
|
|
|
// ValidateNetMode ensures that the various combinations of requested
|
|
|
|
// network settings are valid.
|
2015-12-18 18:36:17 +00:00
|
|
|
func ValidateNetMode(c *container.Config, hc *container.HostConfig) error {
|
2015-11-01 01:49:14 +00:00
|
|
|
// 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>")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-10 01:40:12 +00:00
|
|
|
if hc.NetworkMode.IsContainer() && c.Hostname != "" {
|
2015-11-01 01:49:14 +00:00
|
|
|
return ErrConflictNetworkHostname
|
|
|
|
}
|
|
|
|
|
2016-03-10 01:40:12 +00:00
|
|
|
if hc.UTSMode.IsHost() && c.Hostname != "" {
|
|
|
|
return ErrConflictUTSHostname
|
|
|
|
}
|
|
|
|
|
2015-11-01 01:49:14 +00:00
|
|
|
if hc.NetworkMode.IsHost() && len(hc.Links) > 0 {
|
|
|
|
return ErrConflictHostNetworkAndLinks
|
|
|
|
}
|
|
|
|
|
|
|
|
if hc.NetworkMode.IsContainer() && len(hc.Links) > 0 {
|
|
|
|
return ErrConflictContainerNetworkAndLinks
|
|
|
|
}
|
|
|
|
|
2016-04-29 05:46:57 +00:00
|
|
|
if hc.NetworkMode.IsContainer() && len(hc.DNS) > 0 {
|
2015-11-01 01:49:14 +00:00
|
|
|
return ErrConflictNetworkAndDNS
|
|
|
|
}
|
|
|
|
|
2016-05-25 01:49:11 +00:00
|
|
|
if hc.NetworkMode.IsContainer() && len(hc.ExtraHosts) > 0 {
|
2015-11-01 01:49:14 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-02-03 20:07:00 +00:00
|
|
|
// ValidateIsolation performs platform specific validation of
|
|
|
|
// isolation in the hostconfig structure. Linux only supports "default"
|
2015-11-01 01:49:14 +00:00
|
|
|
// which is LXC container isolation
|
2016-02-03 20:07:00 +00:00
|
|
|
func ValidateIsolation(hc *container.HostConfig) error {
|
2015-11-01 01:49:14 +00:00
|
|
|
// 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
|
|
|
|
}
|
2016-02-25 01:51:46 +00:00
|
|
|
|
|
|
|
// ValidateQoS performs platform specific validation of the QoS settings
|
|
|
|
// a disk can be limited by either Bps or IOps, but not both.
|
|
|
|
func ValidateQoS(hc *container.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.IOMaximumBandwidth != 0 {
|
|
|
|
return fmt.Errorf("invalid QoS settings: %s does not support --maximum-bandwidth", runtime.GOOS)
|
|
|
|
}
|
|
|
|
|
|
|
|
if hc.IOMaximumIOps != 0 {
|
|
|
|
return fmt.Errorf("invalid QoS settings: %s does not support --maximum-iops", runtime.GOOS)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|