container_windows.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // +build windows
  2. package container
  3. import (
  4. "fmt"
  5. "os"
  6. "path/filepath"
  7. containertypes "github.com/docker/docker/api/types/container"
  8. "github.com/docker/docker/utils"
  9. )
  10. // Container holds fields specific to the Windows implementation. See
  11. // CommonContainer for standard fields common to all containers.
  12. type Container struct {
  13. CommonContainer
  14. // Fields below here are platform specific.
  15. }
  16. // ExitStatus provides exit reasons for a container.
  17. type ExitStatus struct {
  18. // The exit code with which the container exited.
  19. ExitCode int
  20. }
  21. // CreateDaemonEnvironment creates a new environment variable slice for this container.
  22. func (container *Container) CreateDaemonEnvironment(_ bool, linkedEnv []string) []string {
  23. // because the env on the container can override certain default values
  24. // we need to replace the 'env' keys where they match and append anything
  25. // else.
  26. return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env)
  27. }
  28. // UnmountIpcMounts unmounts Ipc related mounts.
  29. // This is a NOOP on windows.
  30. func (container *Container) UnmountIpcMounts(unmount func(pth string) error) {
  31. }
  32. // IpcMounts returns the list of Ipc related mounts.
  33. func (container *Container) IpcMounts() []Mount {
  34. return nil
  35. }
  36. // SecretMount returns the mount for the secret path
  37. func (container *Container) SecretMount() *Mount {
  38. return nil
  39. }
  40. // UnmountSecrets unmounts the fs for secrets
  41. func (container *Container) UnmountSecrets() error {
  42. return nil
  43. }
  44. // DetachAndUnmount unmounts all volumes.
  45. // On Windows it only delegates to `UnmountVolumes` since there is nothing to
  46. // force unmount.
  47. func (container *Container) DetachAndUnmount(volumeEventLog func(name, action string, attributes map[string]string)) error {
  48. return container.UnmountVolumes(volumeEventLog)
  49. }
  50. // TmpfsMounts returns the list of tmpfs mounts
  51. func (container *Container) TmpfsMounts() ([]Mount, error) {
  52. var mounts []Mount
  53. return mounts, nil
  54. }
  55. // UpdateContainer updates configuration of a container
  56. func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error {
  57. container.Lock()
  58. defer container.Unlock()
  59. resources := hostConfig.Resources
  60. if resources.BlkioWeight != 0 || resources.CPUShares != 0 ||
  61. resources.CPUPeriod != 0 || resources.CPUQuota != 0 ||
  62. resources.CpusetCpus != "" || resources.CpusetMems != "" ||
  63. resources.Memory != 0 || resources.MemorySwap != 0 ||
  64. resources.MemoryReservation != 0 || resources.KernelMemory != 0 {
  65. return fmt.Errorf("Resource updating isn't supported on Windows")
  66. }
  67. // update HostConfig of container
  68. if hostConfig.RestartPolicy.Name != "" {
  69. if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() {
  70. return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container")
  71. }
  72. container.HostConfig.RestartPolicy = hostConfig.RestartPolicy
  73. }
  74. return nil
  75. }
  76. // cleanResourcePath cleans a resource path by removing C:\ syntax, and prepares
  77. // to combine with a volume path
  78. func cleanResourcePath(path string) string {
  79. if len(path) >= 2 {
  80. c := path[0]
  81. if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
  82. path = path[2:]
  83. }
  84. }
  85. return filepath.Join(string(os.PathSeparator), path)
  86. }
  87. // BuildHostnameFile writes the container's hostname file.
  88. func (container *Container) BuildHostnameFile() error {
  89. return nil
  90. }
  91. // canMountFS determines if the file system for the container
  92. // can be mounted locally. In the case of Windows, this is not possible
  93. // for Hyper-V containers during WORKDIR execution for example.
  94. func (container *Container) canMountFS() bool {
  95. return !containertypes.Isolation.IsHyperV(container.HostConfig.Isolation)
  96. }
  97. // EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network
  98. func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
  99. return true
  100. }