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