github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/container/container_windows.go (about) 1 // +build windows 2 3 package container 4 5 import ( 6 "fmt" 7 "os" 8 "path/filepath" 9 10 containertypes "github.com/docker/docker/api/types/container" 11 "github.com/docker/docker/utils" 12 "github.com/docker/docker/volume" 13 ) 14 15 // Container holds fields specific to the Windows implementation. See 16 // CommonContainer for standard fields common to all containers. 17 type Container struct { 18 CommonContainer 19 20 // Fields below here are platform specific. 21 } 22 23 // ExitStatus provides exit reasons for a container. 24 type ExitStatus struct { 25 // The exit code with which the container exited. 26 ExitCode int 27 } 28 29 // CreateDaemonEnvironment creates a new environment variable slice for this container. 30 func (container *Container) CreateDaemonEnvironment(_ bool, linkedEnv []string) []string { 31 // because the env on the container can override certain default values 32 // we need to replace the 'env' keys where they match and append anything 33 // else. 34 return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env) 35 } 36 37 // UnmountIpcMounts unmounts Ipc related mounts. 38 // This is a NOOP on windows. 39 func (container *Container) UnmountIpcMounts(unmount func(pth string) error) { 40 } 41 42 // IpcMounts returns the list of Ipc related mounts. 43 func (container *Container) IpcMounts() []Mount { 44 return nil 45 } 46 47 // UnmountVolumes explicitly unmounts volumes from the container. 48 func (container *Container) UnmountVolumes(forceSyscall bool, volumeEventLog func(name, action string, attributes map[string]string)) error { 49 var ( 50 volumeMounts []volume.MountPoint 51 err error 52 ) 53 54 for _, mntPoint := range container.MountPoints { 55 // Do not attempt to get the mountpoint destination on the host as it 56 // is not accessible on Windows in the case that a container is running. 57 // (It's a special reparse point which doesn't have any contextual meaning). 58 volumeMounts = append(volumeMounts, volume.MountPoint{Volume: mntPoint.Volume, ID: mntPoint.ID}) 59 } 60 61 // atm, this is a no-op. 62 if volumeMounts, err = appendNetworkMounts(container, volumeMounts); err != nil { 63 return err 64 } 65 66 for _, volumeMount := range volumeMounts { 67 if volumeMount.Volume != nil { 68 if err := volumeMount.Volume.Unmount(volumeMount.ID); err != nil { 69 return err 70 } 71 volumeMount.ID = "" 72 73 attributes := map[string]string{ 74 "driver": volumeMount.Volume.DriverName(), 75 "container": container.ID, 76 } 77 volumeEventLog(volumeMount.Volume.Name(), "unmount", attributes) 78 } 79 } 80 81 return nil 82 } 83 84 // TmpfsMounts returns the list of tmpfs mounts 85 func (container *Container) TmpfsMounts() ([]Mount, error) { 86 var mounts []Mount 87 return mounts, nil 88 } 89 90 // UpdateContainer updates configuration of a container 91 func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error { 92 container.Lock() 93 defer container.Unlock() 94 resources := hostConfig.Resources 95 if resources.BlkioWeight != 0 || resources.CPUShares != 0 || 96 resources.CPUPeriod != 0 || resources.CPUQuota != 0 || 97 resources.CpusetCpus != "" || resources.CpusetMems != "" || 98 resources.Memory != 0 || resources.MemorySwap != 0 || 99 resources.MemoryReservation != 0 || resources.KernelMemory != 0 { 100 return fmt.Errorf("Resource updating isn't supported on Windows") 101 } 102 // update HostConfig of container 103 if hostConfig.RestartPolicy.Name != "" { 104 if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() { 105 return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container") 106 } 107 container.HostConfig.RestartPolicy = hostConfig.RestartPolicy 108 } 109 return nil 110 } 111 112 // appendNetworkMounts appends any network mounts to the array of mount points passed in. 113 // Windows does not support network mounts (not to be confused with SMB network mounts), so 114 // this is a no-op. 115 func appendNetworkMounts(container *Container, volumeMounts []volume.MountPoint) ([]volume.MountPoint, error) { 116 return volumeMounts, nil 117 } 118 119 // cleanResourcePath cleans a resource path by removing C:\ syntax, and prepares 120 // to combine with a volume path 121 func cleanResourcePath(path string) string { 122 if len(path) >= 2 { 123 c := path[0] 124 if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') { 125 path = path[2:] 126 } 127 } 128 return filepath.Join(string(os.PathSeparator), path) 129 } 130 131 // BuildHostnameFile writes the container's hostname file. 132 func (container *Container) BuildHostnameFile() error { 133 return nil 134 } 135 136 // canMountFS determines if the file system for the container 137 // can be mounted locally. In the case of Windows, this is not possible 138 // for Hyper-V containers during WORKDIR execution for example. 139 func (container *Container) canMountFS() bool { 140 return !containertypes.Isolation.IsHyperV(container.HostConfig.Isolation) 141 } 142 143 // EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network 144 func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool { 145 return true 146 }