hostconfig_unix.go 2.8 KB

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