hostconfig_windows.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package runconfig
  2. import (
  3. "fmt"
  4. "github.com/docker/docker/api/types/container"
  5. "github.com/docker/docker/pkg/sysinfo"
  6. )
  7. // DefaultDaemonNetworkMode returns the default network stack the daemon should
  8. // use.
  9. func DefaultDaemonNetworkMode() container.NetworkMode {
  10. return container.NetworkMode("nat")
  11. }
  12. // IsPreDefinedNetwork indicates if a network is predefined by the daemon
  13. func IsPreDefinedNetwork(network string) bool {
  14. return !container.NetworkMode(network).IsUserDefined()
  15. }
  16. // validateNetMode ensures that the various combinations of requested
  17. // network settings are valid.
  18. func validateNetMode(c *container.Config, hc *container.HostConfig) error {
  19. if hc == nil {
  20. return nil
  21. }
  22. err := validateNetContainerMode(c, hc)
  23. if err != nil {
  24. return err
  25. }
  26. if hc.NetworkMode.IsContainer() && hc.Isolation.IsHyperV() {
  27. return fmt.Errorf("Using the network stack of another container is not supported while using Hyper-V Containers")
  28. }
  29. return nil
  30. }
  31. // validateIsolation performs platform specific validation of the
  32. // isolation in the hostconfig structure. Windows supports 'default' (or
  33. // blank), 'process', or 'hyperv'.
  34. func validateIsolation(hc *container.HostConfig) error {
  35. // We may not be passed a host config, such as in the case of docker commit
  36. if hc == nil {
  37. return nil
  38. }
  39. if !hc.Isolation.IsValid() {
  40. return fmt.Errorf("Invalid isolation: %q. Windows supports 'default', 'process', or 'hyperv'", hc.Isolation)
  41. }
  42. return nil
  43. }
  44. // validateQoS performs platform specific validation of the Qos settings
  45. func validateQoS(hc *container.HostConfig) error {
  46. return nil
  47. }
  48. // validateResources performs platform specific validation of the resource settings
  49. func validateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error {
  50. // We may not be passed a host config, such as in the case of docker commit
  51. if hc == nil {
  52. return nil
  53. }
  54. if hc.Resources.CPURealtimePeriod != 0 {
  55. return fmt.Errorf("Windows does not support CPU real-time period")
  56. }
  57. if hc.Resources.CPURealtimeRuntime != 0 {
  58. return fmt.Errorf("Windows does not support CPU real-time runtime")
  59. }
  60. return nil
  61. }
  62. // validatePrivileged performs platform specific validation of the Privileged setting
  63. func validatePrivileged(hc *container.HostConfig) error {
  64. // We may not be passed a host config, such as in the case of docker commit
  65. if hc == nil {
  66. return nil
  67. }
  68. if hc.Privileged {
  69. return fmt.Errorf("Windows does not support privileged mode")
  70. }
  71. return nil
  72. }
  73. // validateReadonlyRootfs performs platform specific validation of the ReadonlyRootfs setting
  74. func validateReadonlyRootfs(hc *container.HostConfig) error {
  75. // We may not be passed a host config, such as in the case of docker commit
  76. if hc == nil {
  77. return nil
  78. }
  79. if hc.ReadonlyRootfs {
  80. return fmt.Errorf("Windows does not support root filesystem in read-only mode")
  81. }
  82. return nil
  83. }