2016-03-25 19:38:00 -04:00
|
|
|
// +build !windows,!solaris
|
2015-06-23 13:13:42 -04:00
|
|
|
|
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
2015-10-31 21:49:14 -04:00
|
|
|
"fmt"
|
|
|
|
"runtime"
|
2015-06-23 13:13:42 -04:00
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2016-06-07 15:05:43 -04:00
|
|
|
"github.com/docker/docker/pkg/sysinfo"
|
2015-12-18 13:36:17 -05:00
|
|
|
)
|
2015-06-23 13:13:42 -04:00
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
// DefaultDaemonNetworkMode returns the default network stack the daemon should
|
|
|
|
// use.
|
2015-12-18 13:36:17 -05:00
|
|
|
func DefaultDaemonNetworkMode() container.NetworkMode {
|
|
|
|
return container.NetworkMode("bridge")
|
2015-09-25 06:19:17 -04:00
|
|
|
}
|
|
|
|
|
2015-10-25 19:09:54 -04:00
|
|
|
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
|
|
|
|
func IsPreDefinedNetwork(network string) bool {
|
2015-12-18 13:36:17 -05:00
|
|
|
n := container.NetworkMode(network)
|
2017-03-09 14:52:25 -05:00
|
|
|
return n.IsBridge() || n.IsHost() || n.IsNone() || n.IsDefault()
|
2015-10-25 19:09:54 -04:00
|
|
|
}
|
|
|
|
|
2017-03-10 12:39:22 -05:00
|
|
|
// validateNetMode ensures that the various combinations of requested
|
2015-10-31 21:49:14 -04:00
|
|
|
// network settings are valid.
|
2017-03-10 12:39:22 -05:00
|
|
|
func validateNetMode(c *container.Config, hc *container.HostConfig) error {
|
2015-10-31 21:49:14 -04:00
|
|
|
// We may not be passed a host config, such as in the case of docker commit
|
|
|
|
if hc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-10 12:39:22 -05:00
|
|
|
err := validateNetContainerMode(c, hc)
|
2017-02-28 23:03:43 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-10-31 21:49:14 -04:00
|
|
|
}
|
|
|
|
|
2016-03-09 20:40:12 -05:00
|
|
|
if hc.UTSMode.IsHost() && c.Hostname != "" {
|
|
|
|
return ErrConflictUTSHostname
|
|
|
|
}
|
|
|
|
|
2015-10-31 21:49:14 -04:00
|
|
|
if hc.NetworkMode.IsHost() && len(hc.Links) > 0 {
|
|
|
|
return ErrConflictHostNetworkAndLinks
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-10 12:39:22 -05:00
|
|
|
// validateIsolation performs platform specific validation of
|
2016-02-03 15:07:00 -05:00
|
|
|
// isolation in the hostconfig structure. Linux only supports "default"
|
2015-10-31 21:49:14 -04:00
|
|
|
// which is LXC container isolation
|
2017-03-10 12:39:22 -05:00
|
|
|
func validateIsolation(hc *container.HostConfig) error {
|
2015-10-31 21:49:14 -04: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() {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Invalid isolation: %q - %s only supports 'default'", hc.Isolation, runtime.GOOS)
|
2015-10-31 21:49:14 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2016-02-24 20:51:46 -05:00
|
|
|
|
2017-03-10 12:39:22 -05:00
|
|
|
// validateQoS performs platform specific validation of the QoS settings
|
|
|
|
func validateQoS(hc *container.HostConfig) error {
|
2016-02-24 20:51:46 -05:00
|
|
|
// 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 {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Invalid QoS settings: %s does not support configuration of maximum bandwidth", runtime.GOOS)
|
2016-02-24 20:51:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if hc.IOMaximumIOps != 0 {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Invalid QoS settings: %s does not support configuration of maximum IOPs", runtime.GOOS)
|
2016-02-24 20:51:46 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2016-06-07 15:05:43 -04:00
|
|
|
|
2017-03-10 12:39:22 -05:00
|
|
|
// validateResources performs platform specific validation of the resource settings
|
2016-06-07 15:05:43 -04:00
|
|
|
// cpu-rt-runtime and cpu-rt-period can not be greater than their parent, cpu-rt-runtime requires sys_nice
|
2017-03-10 12:39:22 -05:00
|
|
|
func validateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error {
|
2016-06-07 15:05:43 -04:00
|
|
|
// We may not be passed a host config, such as in the case of docker commit
|
|
|
|
if hc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if hc.Resources.CPURealtimePeriod > 0 && !si.CPURealtimePeriod {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Your kernel does not support cgroup cpu real-time period")
|
2016-06-07 15:05:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if hc.Resources.CPURealtimeRuntime > 0 && !si.CPURealtimeRuntime {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Your kernel does not support cgroup cpu real-time runtime")
|
2016-06-07 15:05:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if hc.Resources.CPURealtimePeriod != 0 && hc.Resources.CPURealtimeRuntime != 0 && hc.Resources.CPURealtimeRuntime > hc.Resources.CPURealtimePeriod {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("cpu real-time runtime cannot be higher than cpu real-time period")
|
2016-06-07 15:05:43 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2017-03-10 12:39:22 -05:00
|
|
|
|
|
|
|
// validatePrivileged performs platform specific validation of the Privileged setting
|
|
|
|
func validatePrivileged(hc *container.HostConfig) error {
|
|
|
|
return nil
|
|
|
|
}
|
2017-05-08 12:29:37 -04:00
|
|
|
|
|
|
|
// validateReadonlyRootfs performs platform specific validation of the ReadonlyRootfs setting
|
|
|
|
func validateReadonlyRootfs(hc *container.HostConfig) error {
|
|
|
|
return nil
|
|
|
|
}
|