hostconfig_unix.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // +build !windows,!solaris
  2. package 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 container.NetworkMode("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. // We may not be passed a host config, such as in the case of docker commit
  23. if hc == nil {
  24. return nil
  25. }
  26. err := validateNetContainerMode(c, hc)
  27. if err != nil {
  28. return err
  29. }
  30. if hc.UTSMode.IsHost() && c.Hostname != "" {
  31. return ErrConflictUTSHostname
  32. }
  33. if hc.NetworkMode.IsHost() && len(hc.Links) > 0 {
  34. return ErrConflictHostNetworkAndLinks
  35. }
  36. return nil
  37. }
  38. // validateIsolation performs platform specific validation of
  39. // isolation in the hostconfig structure. Linux only supports "default"
  40. // which is LXC container isolation
  41. func validateIsolation(hc *container.HostConfig) error {
  42. // We may not be passed a host config, such as in the case of docker commit
  43. if hc == nil {
  44. return nil
  45. }
  46. if !hc.Isolation.IsValid() {
  47. return fmt.Errorf("Invalid isolation: %q - %s only supports 'default'", hc.Isolation, runtime.GOOS)
  48. }
  49. return nil
  50. }
  51. // validateQoS performs platform specific validation of the QoS settings
  52. func validateQoS(hc *container.HostConfig) error {
  53. // We may not be passed a host config, such as in the case of docker commit
  54. if hc == nil {
  55. return nil
  56. }
  57. if hc.IOMaximumBandwidth != 0 {
  58. return fmt.Errorf("Invalid QoS settings: %s does not support configuration of maximum bandwidth", runtime.GOOS)
  59. }
  60. if hc.IOMaximumIOps != 0 {
  61. return fmt.Errorf("Invalid QoS settings: %s does not support configuration of maximum IOPs", runtime.GOOS)
  62. }
  63. return nil
  64. }
  65. // validateResources performs platform specific validation of the resource settings
  66. // cpu-rt-runtime and cpu-rt-period can not be greater than their parent, cpu-rt-runtime requires sys_nice
  67. func validateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error {
  68. // We may not be passed a host config, such as in the case of docker commit
  69. if hc == nil {
  70. return nil
  71. }
  72. if hc.Resources.CPURealtimePeriod > 0 && !si.CPURealtimePeriod {
  73. return fmt.Errorf("Your kernel does not support cgroup cpu real-time period")
  74. }
  75. if hc.Resources.CPURealtimeRuntime > 0 && !si.CPURealtimeRuntime {
  76. return fmt.Errorf("Your kernel does not support cgroup cpu real-time runtime")
  77. }
  78. if hc.Resources.CPURealtimePeriod != 0 && hc.Resources.CPURealtimeRuntime != 0 && hc.Resources.CPURealtimeRuntime > hc.Resources.CPURealtimePeriod {
  79. return fmt.Errorf("cpu real-time runtime cannot be higher than cpu real-time period")
  80. }
  81. return nil
  82. }
  83. // validatePrivileged performs platform specific validation of the Privileged setting
  84. func validatePrivileged(hc *container.HostConfig) error {
  85. return nil
  86. }
  87. // validateReadonlyRootfs performs platform specific validation of the ReadonlyRootfs setting
  88. func validateReadonlyRootfs(hc *container.HostConfig) error {
  89. return nil
  90. }