github.com/slava-ustovytski/docker@v1.8.2-rc1/daemon/container_windows.go (about) 1 // +build windows 2 3 package daemon 4 5 import ( 6 "fmt" 7 "path/filepath" 8 "strings" 9 10 "github.com/docker/docker/daemon/execdriver" 11 "github.com/docker/docker/daemon/graphdriver/windows" 12 "github.com/docker/docker/image" 13 "github.com/docker/docker/pkg/archive" 14 "github.com/microsoft/hcsshim" 15 ) 16 17 // This is deliberately empty on Windows as the default path will be set by 18 // the container. Docker has no context of what the default path should be. 19 const DefaultPathEnv = "" 20 21 type Container struct { 22 CommonContainer 23 24 // Fields below here are platform specific. 25 26 // TODO Windows. Further factoring out of unused fields will be necessary. 27 28 // ---- START OF TEMPORARY DECLARATION ---- 29 // TODO Windows. Temporarily keeping fields in to assist in compilation 30 // of the daemon on Windows without affecting many other files in a single 31 // PR, thus making code review significantly harder. These lines will be 32 // removed in subsequent PRs. 33 34 AppArmorProfile string 35 // ---- END OF TEMPORARY DECLARATION ---- 36 37 } 38 39 func killProcessDirectly(container *Container) error { 40 return nil 41 } 42 43 func (container *Container) setupContainerDns() error { 44 return nil 45 } 46 47 func (container *Container) updateParentsHosts() error { 48 return nil 49 } 50 51 func (container *Container) setupLinkedContainers() ([]string, error) { 52 return nil, nil 53 } 54 55 func (container *Container) createDaemonEnvironment(linkedEnv []string) []string { 56 // On Windows, nothing to link. Just return the container environment. 57 return container.Config.Env 58 } 59 60 func (container *Container) initializeNetworking() error { 61 return nil 62 } 63 64 func (container *Container) setupWorkingDirectory() error { 65 return nil 66 } 67 68 func populateCommand(c *Container, env []string) error { 69 en := &execdriver.Network{ 70 Mtu: c.daemon.config.Mtu, 71 Interface: nil, 72 } 73 74 parts := strings.SplitN(string(c.hostConfig.NetworkMode), ":", 2) 75 switch parts[0] { 76 77 case "none": 78 case "default", "": // empty string to support existing containers 79 if !c.Config.NetworkDisabled { 80 en.Interface = &execdriver.NetworkInterface{ 81 MacAddress: c.Config.MacAddress, 82 Bridge: c.daemon.config.Bridge.VirtualSwitchName, 83 } 84 } 85 default: 86 return fmt.Errorf("invalid network mode: %s", c.hostConfig.NetworkMode) 87 } 88 89 pid := &execdriver.Pid{} 90 91 // TODO Windows. This can probably be factored out. 92 pid.HostPid = c.hostConfig.PidMode.IsHost() 93 94 // TODO Windows. Resource controls to be implemented later. 95 resources := &execdriver.Resources{} 96 97 // TODO Windows. Further refactoring required (privileged/user) 98 processConfig := execdriver.ProcessConfig{ 99 Privileged: c.hostConfig.Privileged, 100 Entrypoint: c.Path, 101 Arguments: c.Args, 102 Tty: c.Config.Tty, 103 User: c.Config.User, 104 ConsoleSize: c.hostConfig.ConsoleSize, 105 } 106 107 processConfig.Env = env 108 109 var layerFolder string 110 var layerPaths []string 111 112 // The following is specific to the Windows driver. We do this to 113 // enable VFS to continue operating for development purposes. 114 if wd, ok := c.daemon.driver.(*windows.WindowsGraphDriver); ok { 115 var err error 116 var img *image.Image 117 var ids []string 118 119 if img, err = c.daemon.graph.Get(c.ImageID); err != nil { 120 return fmt.Errorf("Failed to graph.Get on ImageID %s - %s", c.ImageID, err) 121 } 122 if ids, err = c.daemon.graph.ParentLayerIds(img); err != nil { 123 return fmt.Errorf("Failed to get parentlayer ids %s", img.ID) 124 } 125 layerPaths = wd.LayerIdsToPaths(ids) 126 layerFolder = filepath.Join(wd.Info().HomeDir, filepath.Base(c.ID)) 127 } 128 129 // TODO Windows: Factor out remainder of unused fields. 130 c.command = &execdriver.Command{ 131 ID: c.ID, 132 Rootfs: c.RootfsPath(), 133 ReadonlyRootfs: c.hostConfig.ReadonlyRootfs, 134 InitPath: "/.dockerinit", 135 WorkingDir: c.Config.WorkingDir, 136 Network: en, 137 Pid: pid, 138 Resources: resources, 139 CapAdd: c.hostConfig.CapAdd.Slice(), 140 CapDrop: c.hostConfig.CapDrop.Slice(), 141 ProcessConfig: processConfig, 142 ProcessLabel: c.GetProcessLabel(), 143 MountLabel: c.GetMountLabel(), 144 FirstStart: !c.HasBeenStartedBefore, 145 LayerFolder: layerFolder, 146 LayerPaths: layerPaths, 147 } 148 149 return nil 150 } 151 152 // GetSize, return real size, virtual size 153 func (container *Container) GetSize() (int64, int64) { 154 // TODO Windows 155 return 0, 0 156 } 157 158 func (container *Container) AllocateNetwork() error { 159 return nil 160 } 161 162 func (container *Container) ExportRw() (archive.Archive, error) { 163 if container.IsRunning() { 164 return nil, fmt.Errorf("Cannot export a running container.") 165 } 166 // TODO Windows. Implementation (different to Linux) 167 return nil, nil 168 } 169 170 func (container *Container) ReleaseNetwork() { 171 } 172 173 func (container *Container) RestoreNetwork() error { 174 return nil 175 } 176 177 func disableAllActiveLinks(container *Container) { 178 } 179 180 func (container *Container) DisableLink(name string) { 181 } 182 183 func (container *Container) UnmountVolumes(forceSyscall bool) error { 184 return nil 185 } 186 187 func (container *Container) PrepareStorage() error { 188 if wd, ok := container.daemon.driver.(*windows.WindowsGraphDriver); ok { 189 // Get list of paths to parent layers. 190 var ids []string 191 if container.ImageID != "" { 192 img, err := container.daemon.graph.Get(container.ImageID) 193 if err != nil { 194 return err 195 } 196 197 ids, err = container.daemon.graph.ParentLayerIds(img) 198 if err != nil { 199 return err 200 } 201 } 202 203 if err := hcsshim.PrepareLayer(wd.Info(), container.ID, wd.LayerIdsToPaths(ids)); err != nil { 204 return err 205 } 206 } 207 return nil 208 } 209 210 func (container *Container) CleanupStorage() error { 211 if wd, ok := container.daemon.driver.(*windows.WindowsGraphDriver); ok { 212 return hcsshim.UnprepareLayer(wd.Info(), container.ID) 213 } 214 return nil 215 }