container_windows.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // +build windows
  2. package daemon
  3. import (
  4. "strings"
  5. "github.com/docker/docker/daemon/execdriver"
  6. derr "github.com/docker/docker/errors"
  7. "github.com/docker/libnetwork"
  8. )
  9. // DefaultPathEnv is deliberately empty on Windows as the default path will be set by
  10. // the container. Docker has no context of what the default path should be.
  11. const DefaultPathEnv = ""
  12. // Container holds fields specific to the Windows implementation. See
  13. // CommonContainer for standard fields common to all containers.
  14. type Container struct {
  15. CommonContainer
  16. // Fields below here are platform specific.
  17. }
  18. func killProcessDirectly(container *Container) error {
  19. return nil
  20. }
  21. func (container *Container) setupLinkedContainers() ([]string, error) {
  22. return nil, nil
  23. }
  24. func (container *Container) createDaemonEnvironment(linkedEnv []string) []string {
  25. // On Windows, nothing to link. Just return the container environment.
  26. return container.Config.Env
  27. }
  28. func (container *Container) initializeNetworking() error {
  29. return nil
  30. }
  31. // ConnectToNetwork connects a container to the network
  32. func (container *Container) ConnectToNetwork(idOrName string) error {
  33. return nil
  34. }
  35. // DisconnectFromNetwork disconnects a container from, the network
  36. func (container *Container) DisconnectFromNetwork(n libnetwork.Network) error {
  37. return nil
  38. }
  39. func (container *Container) setupWorkingDirectory() error {
  40. return nil
  41. }
  42. func populateCommand(c *Container, env []string) error {
  43. en := &execdriver.Network{
  44. Interface: nil,
  45. }
  46. parts := strings.SplitN(string(c.hostConfig.NetworkMode), ":", 2)
  47. switch parts[0] {
  48. case "none":
  49. case "default", "": // empty string to support existing containers
  50. if !c.Config.NetworkDisabled {
  51. en.Interface = &execdriver.NetworkInterface{
  52. MacAddress: c.Config.MacAddress,
  53. Bridge: c.daemon.configStore.Bridge.VirtualSwitchName,
  54. PortBindings: c.hostConfig.PortBindings,
  55. // TODO Windows. Include IPAddress. There already is a
  56. // property IPAddress on execDrive.CommonNetworkInterface,
  57. // but there is no CLI option in docker to pass through
  58. // an IPAddress on docker run.
  59. }
  60. }
  61. default:
  62. return derr.ErrorCodeInvalidNetworkMode.WithArgs(c.hostConfig.NetworkMode)
  63. }
  64. pid := &execdriver.Pid{}
  65. // TODO Windows. This can probably be factored out.
  66. pid.HostPid = c.hostConfig.PidMode.IsHost()
  67. // TODO Windows. More resource controls to be implemented later.
  68. resources := &execdriver.Resources{
  69. CPUShares: c.hostConfig.CPUShares,
  70. }
  71. // TODO Windows. Further refactoring required (privileged/user)
  72. processConfig := execdriver.ProcessConfig{
  73. Privileged: c.hostConfig.Privileged,
  74. Entrypoint: c.Path,
  75. Arguments: c.Args,
  76. Tty: c.Config.Tty,
  77. User: c.Config.User,
  78. ConsoleSize: c.hostConfig.ConsoleSize,
  79. }
  80. processConfig.Env = env
  81. var layerPaths []string
  82. img, err := c.daemon.graph.Get(c.ImageID)
  83. if err != nil {
  84. return derr.ErrorCodeGetGraph.WithArgs(c.ImageID, err)
  85. }
  86. for i := img; i != nil && err == nil; i, err = c.daemon.graph.GetParent(i) {
  87. lp, err := c.daemon.driver.Get(i.ID, "")
  88. if err != nil {
  89. return derr.ErrorCodeGetLayer.WithArgs(c.daemon.driver.String(), i.ID, err)
  90. }
  91. layerPaths = append(layerPaths, lp)
  92. err = c.daemon.driver.Put(i.ID)
  93. if err != nil {
  94. return derr.ErrorCodePutLayer.WithArgs(c.daemon.driver.String(), i.ID, err)
  95. }
  96. }
  97. m, err := c.daemon.driver.GetMetadata(c.ID)
  98. if err != nil {
  99. return derr.ErrorCodeGetLayerMetadata.WithArgs(err)
  100. }
  101. layerFolder := m["dir"]
  102. // TODO Windows: Factor out remainder of unused fields.
  103. c.command = &execdriver.Command{
  104. ID: c.ID,
  105. Rootfs: c.rootfsPath(),
  106. ReadonlyRootfs: c.hostConfig.ReadonlyRootfs,
  107. InitPath: "/.dockerinit",
  108. WorkingDir: c.Config.WorkingDir,
  109. Network: en,
  110. Pid: pid,
  111. Resources: resources,
  112. CapAdd: c.hostConfig.CapAdd.Slice(),
  113. CapDrop: c.hostConfig.CapDrop.Slice(),
  114. ProcessConfig: processConfig,
  115. ProcessLabel: c.getProcessLabel(),
  116. MountLabel: c.getMountLabel(),
  117. FirstStart: !c.HasBeenStartedBefore,
  118. LayerFolder: layerFolder,
  119. LayerPaths: layerPaths,
  120. }
  121. return nil
  122. }
  123. // GetSize returns real size & virtual size
  124. func (container *Container) getSize() (int64, int64) {
  125. // TODO Windows
  126. return 0, 0
  127. }
  128. // setNetworkNamespaceKey is a no-op on Windows.
  129. func (container *Container) setNetworkNamespaceKey(pid int) error {
  130. return nil
  131. }
  132. // allocateNetwork is a no-op on Windows.
  133. func (container *Container) allocateNetwork() error {
  134. return nil
  135. }
  136. func (container *Container) updateNetwork() error {
  137. return nil
  138. }
  139. func (container *Container) releaseNetwork() {
  140. }
  141. func (container *Container) unmountVolumes(forceSyscall bool) error {
  142. return nil
  143. }
  144. // prepareMountPoints is a no-op on Windows
  145. func (container *Container) prepareMountPoints() error {
  146. return nil
  147. }
  148. // removeMountPoints is a no-op on Windows.
  149. func (container *Container) removeMountPoints(_ bool) error {
  150. return nil
  151. }
  152. func (container *Container) setupIpcDirs() error {
  153. return nil
  154. }
  155. func (container *Container) unmountIpcMounts() error {
  156. return nil
  157. }
  158. func (container *Container) ipcMounts() []execdriver.Mount {
  159. return nil
  160. }
  161. func getDefaultRouteMtu() (int, error) {
  162. return -1, errSystemNotSupported
  163. }