container_windows.go 3.4 KB

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