4785f1a7 |
// +build !windows |
c5e6a4b3 |
|
4f0d95fa |
package runconfig // import "github.com/docker/docker/runconfig" |
c5e6a4b3 |
import ( |
ee6c3580 |
"fmt"
"runtime" |
c5e6a4b3 |
|
91e197d6 |
"github.com/docker/docker/api/types/container" |
56f77d5a |
"github.com/docker/docker/pkg/sysinfo" |
7ac4232e |
) |
c5e6a4b3 |
|
5170a2c0 |
// DefaultDaemonNetworkMode returns the default network stack the daemon should
// use. |
7ac4232e |
func DefaultDaemonNetworkMode() container.NetworkMode {
return container.NetworkMode("bridge") |
2ab94e11 |
}
|
ead62b59 |
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
func IsPreDefinedNetwork(network string) bool { |
7ac4232e |
n := container.NetworkMode(network) |
d59d19c3 |
return n.IsBridge() || n.IsHost() || n.IsNone() || n.IsDefault() |
ead62b59 |
}
|
4af3389d |
// validateNetMode ensures that the various combinations of requested |
ee6c3580 |
// network settings are valid. |
4af3389d |
func validateNetMode(c *container.Config, hc *container.HostConfig) error { |
ee6c3580 |
// We may not be passed a host config, such as in the case of docker commit
if hc == nil {
return nil
}
|
4af3389d |
err := validateNetContainerMode(c, hc) |
040afcce |
if err != nil {
return err |
ee6c3580 |
}
|
3f445e63 |
if hc.UTSMode.IsHost() && c.Hostname != "" {
return ErrConflictUTSHostname
}
|
ee6c3580 |
if hc.NetworkMode.IsHost() && len(hc.Links) > 0 {
return ErrConflictHostNetworkAndLinks
}
return nil
}
|
4af3389d |
// validateIsolation performs platform specific validation of |
d4b07324 |
// isolation in the hostconfig structure. Linux only supports "default" |
ee6c3580 |
// which is LXC container isolation |
4af3389d |
func validateIsolation(hc *container.HostConfig) error { |
ee6c3580 |
// 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() { |
92291a73 |
return fmt.Errorf("Invalid isolation: %q - %s only supports 'default'", hc.Isolation, runtime.GOOS) |
ee6c3580 |
}
return nil
} |
8df20663 |
|
4af3389d |
// validateQoS performs platform specific validation of the QoS settings
func validateQoS(hc *container.HostConfig) error { |
8df20663 |
// 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 { |
92291a73 |
return fmt.Errorf("Invalid QoS settings: %s does not support configuration of maximum bandwidth", runtime.GOOS) |
8df20663 |
}
if hc.IOMaximumIOps != 0 { |
92291a73 |
return fmt.Errorf("Invalid QoS settings: %s does not support configuration of maximum IOPs", runtime.GOOS) |
8df20663 |
}
return nil
} |
56f77d5a |
|
4af3389d |
// validateResources performs platform specific validation of the resource settings |
56f77d5a |
// cpu-rt-runtime and cpu-rt-period can not be greater than their parent, cpu-rt-runtime requires sys_nice |
4af3389d |
func validateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error { |
56f77d5a |
// 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 { |
92291a73 |
return fmt.Errorf("Your kernel does not support cgroup cpu real-time period") |
56f77d5a |
}
if hc.Resources.CPURealtimeRuntime > 0 && !si.CPURealtimeRuntime { |
92291a73 |
return fmt.Errorf("Your kernel does not support cgroup cpu real-time runtime") |
56f77d5a |
}
if hc.Resources.CPURealtimePeriod != 0 && hc.Resources.CPURealtimeRuntime != 0 && hc.Resources.CPURealtimeRuntime > hc.Resources.CPURealtimePeriod { |
92291a73 |
return fmt.Errorf("cpu real-time runtime cannot be higher than cpu real-time period") |
56f77d5a |
}
return nil
} |
4af3389d |
// validatePrivileged performs platform specific validation of the Privileged setting
func validatePrivileged(hc *container.HostConfig) error {
return nil
} |
6f7dc658 |
// validateReadonlyRootfs performs platform specific validation of the ReadonlyRootfs setting
func validateReadonlyRootfs(hc *container.HostConfig) error {
return nil
} |