github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/daemon/oci_windows.go (about) 1 package daemon 2 3 import ( 4 "syscall" 5 6 containertypes "github.com/docker/docker/api/types/container" 7 "github.com/docker/docker/container" 8 "github.com/docker/docker/oci" 9 "github.com/opencontainers/runtime-spec/specs-go" 10 ) 11 12 func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) { 13 s := oci.DefaultSpec() 14 15 linkedEnv, err := daemon.setupLinkedContainers(c) 16 if err != nil { 17 return nil, err 18 } 19 20 // TODO Windows - this can be removed. Not used (UID/GID) 21 rootUID, rootGID := daemon.GetRemappedUIDGID() 22 if err := c.SetupWorkingDirectory(rootUID, rootGID); err != nil { 23 return nil, err 24 } 25 26 // In base spec 27 s.Hostname = c.FullHostname() 28 29 // In s.Mounts 30 mounts, err := daemon.setupMounts(c) 31 if err != nil { 32 return nil, err 33 } 34 for _, mount := range mounts { 35 m := specs.Mount{ 36 Source: mount.Source, 37 Destination: mount.Destination, 38 } 39 if !mount.Writable { 40 m.Options = append(m.Options, "ro") 41 } 42 s.Mounts = append(s.Mounts, m) 43 } 44 45 // In s.Process 46 s.Process.Args = append([]string{c.Path}, c.Args...) 47 if !c.Config.ArgsEscaped { 48 s.Process.Args = escapeArgs(s.Process.Args) 49 } 50 s.Process.Cwd = c.Config.WorkingDir 51 if len(s.Process.Cwd) == 0 { 52 // We default to C:\ to workaround the oddity of the case that the 53 // default directory for cmd running as LocalSystem (or 54 // ContainerAdministrator) is c:\windows\system32. Hence docker run 55 // <image> cmd will by default end in c:\windows\system32, rather 56 // than 'root' (/) on Linux. The oddity is that if you have a dockerfile 57 // which has no WORKDIR and has a COPY file ., . will be interpreted 58 // as c:\. Hence, setting it to default of c:\ makes for consistency. 59 s.Process.Cwd = `C:\` 60 } 61 s.Process.Env = c.CreateDaemonEnvironment(c.Config.Tty, linkedEnv) 62 s.Process.ConsoleSize.Height = c.HostConfig.ConsoleSize[0] 63 s.Process.ConsoleSize.Width = c.HostConfig.ConsoleSize[1] 64 s.Process.Terminal = c.Config.Tty 65 s.Process.User.Username = c.Config.User 66 67 // In spec.Root. This is not set for Hyper-V containers 68 isHyperV := false 69 if c.HostConfig.Isolation.IsDefault() { 70 // Container using default isolation, so take the default from the daemon configuration 71 isHyperV = daemon.defaultIsolation.IsHyperV() 72 } else { 73 // Container may be requesting an explicit isolation mode. 74 isHyperV = c.HostConfig.Isolation.IsHyperV() 75 } 76 if !isHyperV { 77 s.Root.Path = c.BaseFS 78 } 79 s.Root.Readonly = false // Windows does not support a read-only root filesystem 80 81 // In s.Windows.Resources 82 // @darrenstahlmsft implement these resources 83 cpuShares := uint16(c.HostConfig.CPUShares) 84 cpuPercent := uint8(c.HostConfig.CPUPercent) 85 memoryLimit := uint64(c.HostConfig.Memory) 86 s.Windows.Resources = &specs.WindowsResources{ 87 CPU: &specs.WindowsCPUResources{ 88 Percent: &cpuPercent, 89 Shares: &cpuShares, 90 }, 91 Memory: &specs.WindowsMemoryResources{ 92 Limit: &memoryLimit, 93 //TODO Reservation: ..., 94 }, 95 Network: &specs.WindowsNetworkResources{ 96 //TODO Bandwidth: ..., 97 }, 98 Storage: &specs.WindowsStorageResources{ 99 Bps: &c.HostConfig.IOMaximumBandwidth, 100 Iops: &c.HostConfig.IOMaximumIOps, 101 }, 102 } 103 return (*specs.Spec)(&s), nil 104 } 105 106 func escapeArgs(args []string) []string { 107 escapedArgs := make([]string, len(args)) 108 for i, a := range args { 109 escapedArgs[i] = syscall.EscapeArg(a) 110 } 111 return escapedArgs 112 } 113 114 // mergeUlimits merge the Ulimits from HostConfig with daemon defaults, and update HostConfig 115 // It will do nothing on non-Linux platform 116 func (daemon *Daemon) mergeUlimits(c *containertypes.HostConfig) { 117 return 118 }