container_windows.go 3.5 KB

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