container_windows.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // +build windows
  2. package container
  3. import (
  4. "fmt"
  5. "os"
  6. "path/filepath"
  7. "github.com/docker/docker/api/types"
  8. containertypes "github.com/docker/docker/api/types/container"
  9. "github.com/docker/docker/pkg/system"
  10. )
  11. const (
  12. containerSecretMountPath = `C:\ProgramData\Docker\secrets`
  13. containerInternalSecretMountPath = `C:\ProgramData\Docker\internal\secrets`
  14. containerInternalConfigsDirPath = `C:\ProgramData\Docker\internal\configs`
  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. // UnmountIpcMount unmounts Ipc related mounts.
  22. // This is a NOOP on windows.
  23. func (container *Container) UnmountIpcMount(unmount func(pth string) error) error {
  24. return nil
  25. }
  26. // IpcMounts returns the list of Ipc related mounts.
  27. func (container *Container) IpcMounts() []Mount {
  28. return nil
  29. }
  30. // CreateSecretSymlinks creates symlinks to files in the secret mount.
  31. func (container *Container) CreateSecretSymlinks() error {
  32. for _, r := range container.SecretReferences {
  33. if r.File == nil {
  34. continue
  35. }
  36. resolvedPath, _, err := container.ResolvePath(getSecretTargetPath(r))
  37. if err != nil {
  38. return err
  39. }
  40. if err := system.MkdirAll(filepath.Dir(resolvedPath), 0, ""); err != nil {
  41. return err
  42. }
  43. if err := os.Symlink(filepath.Join(containerInternalSecretMountPath, r.SecretID), resolvedPath); err != nil {
  44. return err
  45. }
  46. }
  47. return nil
  48. }
  49. // SecretMounts returns the mount for the secret path.
  50. // All secrets are stored in a single mount on Windows. Target symlinks are
  51. // created for each secret, pointing to the files in this mount.
  52. func (container *Container) SecretMounts() []Mount {
  53. var mounts []Mount
  54. if len(container.SecretReferences) > 0 {
  55. mounts = append(mounts, Mount{
  56. Source: container.SecretMountPath(),
  57. Destination: containerInternalSecretMountPath,
  58. Writable: false,
  59. })
  60. }
  61. return mounts
  62. }
  63. // UnmountSecrets unmounts the fs for secrets
  64. func (container *Container) UnmountSecrets() error {
  65. return os.RemoveAll(container.SecretMountPath())
  66. }
  67. // CreateConfigSymlinks creates symlinks to files in the config mount.
  68. func (container *Container) CreateConfigSymlinks() error {
  69. for _, configRef := range container.ConfigReferences {
  70. if configRef.File == nil {
  71. continue
  72. }
  73. resolvedPath, _, err := container.ResolvePath(configRef.File.Name)
  74. if err != nil {
  75. return err
  76. }
  77. if err := system.MkdirAll(filepath.Dir(resolvedPath), 0, ""); err != nil {
  78. return err
  79. }
  80. if err := os.Symlink(filepath.Join(containerInternalConfigsDirPath, configRef.ConfigID), resolvedPath); err != nil {
  81. return err
  82. }
  83. }
  84. return nil
  85. }
  86. // ConfigMounts returns the mount for configs.
  87. // All configs are stored in a single mount on Windows. Target symlinks are
  88. // created for each config, pointing to the files in this mount.
  89. func (container *Container) ConfigMounts() []Mount {
  90. var mounts []Mount
  91. if len(container.ConfigReferences) > 0 {
  92. mounts = append(mounts, Mount{
  93. Source: container.ConfigsDirPath(),
  94. Destination: containerInternalConfigsDirPath,
  95. Writable: false,
  96. })
  97. }
  98. return mounts
  99. }
  100. // DetachAndUnmount unmounts all volumes.
  101. // On Windows it only delegates to `UnmountVolumes` since there is nothing to
  102. // force unmount.
  103. func (container *Container) DetachAndUnmount(volumeEventLog func(name, action string, attributes map[string]string)) error {
  104. return container.UnmountVolumes(volumeEventLog)
  105. }
  106. // TmpfsMounts returns the list of tmpfs mounts
  107. func (container *Container) TmpfsMounts() ([]Mount, error) {
  108. var mounts []Mount
  109. return mounts, nil
  110. }
  111. // UpdateContainer updates configuration of a container. Callers must hold a Lock on the Container.
  112. func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error {
  113. resources := hostConfig.Resources
  114. if resources.CPUShares != 0 ||
  115. resources.Memory != 0 ||
  116. resources.NanoCPUs != 0 ||
  117. resources.CgroupParent != "" ||
  118. resources.BlkioWeight != 0 ||
  119. len(resources.BlkioWeightDevice) != 0 ||
  120. len(resources.BlkioDeviceReadBps) != 0 ||
  121. len(resources.BlkioDeviceWriteBps) != 0 ||
  122. len(resources.BlkioDeviceReadIOps) != 0 ||
  123. len(resources.BlkioDeviceWriteIOps) != 0 ||
  124. resources.CPUPeriod != 0 ||
  125. resources.CPUQuota != 0 ||
  126. resources.CPURealtimePeriod != 0 ||
  127. resources.CPURealtimeRuntime != 0 ||
  128. resources.CpusetCpus != "" ||
  129. resources.CpusetMems != "" ||
  130. len(resources.Devices) != 0 ||
  131. len(resources.DeviceCgroupRules) != 0 ||
  132. resources.DiskQuota != 0 ||
  133. resources.KernelMemory != 0 ||
  134. resources.MemoryReservation != 0 ||
  135. resources.MemorySwap != 0 ||
  136. resources.MemorySwappiness != nil ||
  137. resources.OomKillDisable != nil ||
  138. resources.PidsLimit != 0 ||
  139. len(resources.Ulimits) != 0 ||
  140. resources.CPUCount != 0 ||
  141. resources.CPUPercent != 0 ||
  142. resources.IOMaximumIOps != 0 ||
  143. resources.IOMaximumBandwidth != 0 {
  144. return fmt.Errorf("resource updating isn't supported on Windows")
  145. }
  146. // update HostConfig of container
  147. if hostConfig.RestartPolicy.Name != "" {
  148. if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() {
  149. return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container")
  150. }
  151. container.HostConfig.RestartPolicy = hostConfig.RestartPolicy
  152. }
  153. return nil
  154. }
  155. // BuildHostnameFile writes the container's hostname file.
  156. func (container *Container) BuildHostnameFile() error {
  157. return nil
  158. }
  159. // EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network
  160. func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
  161. return true
  162. }
  163. // GetMountPoints gives a platform specific transformation to types.MountPoint. Callers must hold a Container lock.
  164. func (container *Container) GetMountPoints() []types.MountPoint {
  165. mountPoints := make([]types.MountPoint, 0, len(container.MountPoints))
  166. for _, m := range container.MountPoints {
  167. mountPoints = append(mountPoints, types.MountPoint{
  168. Type: m.Type,
  169. Name: m.Name,
  170. Source: m.Path(),
  171. Destination: m.Destination,
  172. Driver: m.Driver,
  173. RW: m.RW,
  174. })
  175. }
  176. return mountPoints
  177. }