2018-02-05 16:05:59 -05:00
|
|
|
package runconfig // import "github.com/docker/docker/runconfig"
|
2015-06-23 13:13:42 -04:00
|
|
|
|
2015-10-31 21:49:14 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
2015-10-31 22:16:58 -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-09-18 21:21:57 -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 {
|
2021-08-09 05:11:54 -04:00
|
|
|
return "nat"
|
2015-07-09 18:12:36 -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 {
|
2016-03-09 23:33:21 -05:00
|
|
|
return !container.NetworkMode(network).IsUserDefined()
|
2015-10-25 19:09:54 -04:00
|
|
|
}
|
2015-10-31 21:49:14 -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 {
|
2021-08-09 05:11:54 -04:00
|
|
|
if err := validateNetContainerMode(c, hc); err != nil {
|
2017-02-28 23:03:43 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if hc.NetworkMode.IsContainer() && hc.Isolation.IsHyperV() {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Using the network stack of another container is not supported while using Hyper-V Containers")
|
2015-10-31 21:49:14 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-10 12:39:22 -05:00
|
|
|
// validateIsolation performs platform specific validation of the
|
2016-02-03 15:07:00 -05:00
|
|
|
// isolation in the hostconfig structure. Windows supports 'default' (or
|
2015-10-31 22:16:58 -04:00
|
|
|
// blank), 'process', or 'hyperv'.
|
2017-03-10 12:39:22 -05:00
|
|
|
func validateIsolation(hc *container.HostConfig) error {
|
2015-10-31 21:49:14 -04:00
|
|
|
if !hc.Isolation.IsValid() {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Invalid isolation: %q. Windows supports 'default', 'process', or 'hyperv'", hc.Isolation)
|
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
|
2021-08-09 05:11:54 -04:00
|
|
|
func validateQoS(_ *container.HostConfig) error {
|
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
|
2021-08-09 05:11:54 -04:00
|
|
|
func validateResources(hc *container.HostConfig, _ *sysinfo.SysInfo) error {
|
2016-06-07 15:05:43 -04:00
|
|
|
if hc.Resources.CPURealtimePeriod != 0 {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Windows does not support CPU real-time period")
|
2016-06-07 15:05:43 -04:00
|
|
|
}
|
|
|
|
if hc.Resources.CPURealtimeRuntime != 0 {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Windows does not support CPU real-time runtime")
|
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 {
|
|
|
|
if hc.Privileged {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Windows does not support privileged mode")
|
2017-03-10 12:39:22 -05:00
|
|
|
}
|
|
|
|
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 {
|
|
|
|
if hc.ReadonlyRootfs {
|
2017-05-21 13:50:55 -04:00
|
|
|
return fmt.Errorf("Windows does not support root filesystem in read-only mode")
|
2017-05-08 12:29:37 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|