hostconfig_unix.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //go:build !windows
  2. package runconfig // import "github.com/docker/docker/runconfig"
  3. import (
  4. "fmt"
  5. "runtime"
  6. "github.com/docker/docker/api/types/container"
  7. "github.com/docker/docker/api/types/network"
  8. "github.com/docker/docker/pkg/sysinfo"
  9. )
  10. // DefaultDaemonNetworkMode returns the default network stack the daemon should
  11. // use.
  12. func DefaultDaemonNetworkMode() container.NetworkMode {
  13. return network.NetworkBridge
  14. }
  15. // IsPreDefinedNetwork indicates if a network is predefined by the daemon
  16. func IsPreDefinedNetwork(network string) bool {
  17. n := container.NetworkMode(network)
  18. return n.IsBridge() || n.IsHost() || n.IsNone() || n.IsDefault()
  19. }
  20. // validateNetMode ensures that the various combinations of requested
  21. // network settings are valid.
  22. func validateNetMode(c *container.Config, hc *container.HostConfig) error {
  23. err := validateNetContainerMode(c, hc)
  24. if err != nil {
  25. return err
  26. }
  27. if hc.UTSMode.IsHost() && c.Hostname != "" {
  28. return ErrConflictUTSHostname
  29. }
  30. if hc.NetworkMode.IsHost() && len(hc.Links) > 0 {
  31. return ErrConflictHostNetworkAndLinks
  32. }
  33. return nil
  34. }
  35. // validateIsolation performs platform specific validation of
  36. // isolation in the hostconfig structure. Linux only supports "default"
  37. // which is LXC container isolation
  38. func validateIsolation(hc *container.HostConfig) error {
  39. if !hc.Isolation.IsValid() {
  40. return fmt.Errorf("Invalid isolation: %q - %s only supports 'default'", hc.Isolation, runtime.GOOS)
  41. }
  42. return nil
  43. }
  44. // validateQoS performs platform specific validation of the QoS settings
  45. func validateQoS(hc *container.HostConfig) error {
  46. if hc.IOMaximumBandwidth != 0 {
  47. return fmt.Errorf("Invalid QoS settings: %s does not support configuration of maximum bandwidth", runtime.GOOS)
  48. }
  49. if hc.IOMaximumIOps != 0 {
  50. return fmt.Errorf("Invalid QoS settings: %s does not support configuration of maximum IOPs", runtime.GOOS)
  51. }
  52. return nil
  53. }
  54. // validateResources performs platform specific validation of the resource settings
  55. // cpu-rt-runtime and cpu-rt-period can not be greater than their parent, cpu-rt-runtime requires sys_nice
  56. func validateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error {
  57. if (hc.Resources.CPURealtimePeriod != 0 || hc.Resources.CPURealtimeRuntime != 0) && !si.CPURealtime {
  58. return fmt.Errorf("Your kernel does not support CPU real-time scheduler")
  59. }
  60. if hc.Resources.CPURealtimePeriod != 0 && hc.Resources.CPURealtimeRuntime != 0 && hc.Resources.CPURealtimeRuntime > hc.Resources.CPURealtimePeriod {
  61. return fmt.Errorf("cpu real-time runtime cannot be higher than cpu real-time period")
  62. }
  63. return nil
  64. }
  65. // validatePrivileged performs platform specific validation of the Privileged setting
  66. func validatePrivileged(_ *container.HostConfig) error {
  67. return nil
  68. }
  69. // validateReadonlyRootfs performs platform specific validation of the ReadonlyRootfs setting
  70. func validateReadonlyRootfs(_ *container.HostConfig) error {
  71. return nil
  72. }