container_operations_windows.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. package daemon // import "github.com/docker/docker/daemon"
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/docker/docker/container"
  6. "github.com/docker/docker/libnetwork"
  7. "github.com/docker/docker/pkg/system"
  8. "github.com/pkg/errors"
  9. "github.com/sirupsen/logrus"
  10. )
  11. func (daemon *Daemon) setupLinkedContainers(container *container.Container) ([]string, error) {
  12. return nil, nil
  13. }
  14. func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
  15. if len(c.ConfigReferences) == 0 {
  16. return nil
  17. }
  18. localPath := c.ConfigsDirPath()
  19. logrus.Debugf("configs: setting up config dir: %s", localPath)
  20. // create local config root
  21. if err := system.MkdirAllWithACL(localPath, 0, system.SddlAdministratorsLocalSystem); err != nil {
  22. return errors.Wrap(err, "error creating config dir")
  23. }
  24. defer func() {
  25. if setupErr != nil {
  26. if err := os.RemoveAll(localPath); err != nil {
  27. logrus.Errorf("error cleaning up config dir: %s", err)
  28. }
  29. }
  30. }()
  31. if c.DependencyStore == nil {
  32. return fmt.Errorf("config store is not initialized")
  33. }
  34. for _, configRef := range c.ConfigReferences {
  35. // TODO (ehazlett): use type switch when more are supported
  36. if configRef.File == nil {
  37. // Runtime configs are not mounted into the container, but they're
  38. // a valid type of config so we should not error when we encounter
  39. // one.
  40. if configRef.Runtime == nil {
  41. logrus.Error("config target type is not a file or runtime target")
  42. }
  43. // However, in any case, this isn't a file config, so we have no
  44. // further work to do
  45. continue
  46. }
  47. fPath, err := c.ConfigFilePath(*configRef)
  48. if err != nil {
  49. return errors.Wrap(err, "error getting config file path for container")
  50. }
  51. log := logrus.WithFields(logrus.Fields{"name": configRef.File.Name, "path": fPath})
  52. log.Debug("injecting config")
  53. config, err := c.DependencyStore.Configs().Get(configRef.ConfigID)
  54. if err != nil {
  55. return errors.Wrap(err, "unable to get config from config store")
  56. }
  57. if err := os.WriteFile(fPath, config.Spec.Data, configRef.File.Mode); err != nil {
  58. return errors.Wrap(err, "error injecting config")
  59. }
  60. }
  61. return nil
  62. }
  63. func (daemon *Daemon) setupIpcDirs(container *container.Container) error {
  64. return nil
  65. }
  66. // TODO Windows: Fix Post-TP5. This is a hack to allow docker cp to work
  67. // against containers which have volumes. You will still be able to cp
  68. // to somewhere on the container drive, but not to any mounted volumes
  69. // inside the container. Without this fix, docker cp is broken to any
  70. // container which has a volume, regardless of where the file is inside the
  71. // container.
  72. func (daemon *Daemon) mountVolumes(container *container.Container) error {
  73. return nil
  74. }
  75. func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
  76. if len(c.SecretReferences) == 0 {
  77. return nil
  78. }
  79. localMountPath, err := c.SecretMountPath()
  80. if err != nil {
  81. return err
  82. }
  83. logrus.Debugf("secrets: setting up secret dir: %s", localMountPath)
  84. // create local secret root
  85. if err := system.MkdirAllWithACL(localMountPath, 0, system.SddlAdministratorsLocalSystem); err != nil {
  86. return errors.Wrap(err, "error creating secret local directory")
  87. }
  88. defer func() {
  89. if setupErr != nil {
  90. if err := os.RemoveAll(localMountPath); err != nil {
  91. logrus.Errorf("error cleaning up secret mount: %s", err)
  92. }
  93. }
  94. }()
  95. if c.DependencyStore == nil {
  96. return fmt.Errorf("secret store is not initialized")
  97. }
  98. for _, s := range c.SecretReferences {
  99. // TODO (ehazlett): use type switch when more are supported
  100. if s.File == nil {
  101. logrus.Error("secret target type is not a file target")
  102. continue
  103. }
  104. // secrets are created in the SecretMountPath on the host, at a
  105. // single level
  106. fPath, err := c.SecretFilePath(*s)
  107. if err != nil {
  108. return err
  109. }
  110. logrus.WithFields(logrus.Fields{
  111. "name": s.File.Name,
  112. "path": fPath,
  113. }).Debug("injecting secret")
  114. secret, err := c.DependencyStore.Secrets().Get(s.SecretID)
  115. if err != nil {
  116. return errors.Wrap(err, "unable to get secret from secret store")
  117. }
  118. if err := os.WriteFile(fPath, secret.Spec.Data, s.File.Mode); err != nil {
  119. return errors.Wrap(err, "error injecting secret")
  120. }
  121. }
  122. return nil
  123. }
  124. func killProcessDirectly(container *container.Container) error {
  125. return nil
  126. }
  127. func isLinkable(child *container.Container) bool {
  128. return false
  129. }
  130. func enableIPOnPredefinedNetwork() bool {
  131. return true
  132. }
  133. // serviceDiscoveryOnDefaultNetwork indicates if service discovery is supported on the default network
  134. func serviceDiscoveryOnDefaultNetwork() bool {
  135. return true
  136. }
  137. func (daemon *Daemon) setupPathsAndSandboxOptions(container *container.Container, sboxOptions *[]libnetwork.SandboxOption) error {
  138. return nil
  139. }
  140. func (daemon *Daemon) initializeNetworkingPaths(container *container.Container, nc *container.Container) error {
  141. if nc.HostConfig.Isolation.IsHyperV() {
  142. return fmt.Errorf("sharing of hyperv containers network is not supported")
  143. }
  144. container.NetworkSharedContainerID = nc.ID
  145. if nc.NetworkSettings != nil {
  146. for n := range nc.NetworkSettings.Networks {
  147. sn, err := daemon.FindNetwork(n)
  148. if err != nil {
  149. continue
  150. }
  151. ep, err := getEndpointInNetwork(nc.Name, sn)
  152. if err != nil {
  153. continue
  154. }
  155. data, err := ep.DriverInfo()
  156. if err != nil {
  157. continue
  158. }
  159. if data["GW_INFO"] != nil {
  160. gwInfo := data["GW_INFO"].(map[string]interface{})
  161. if gwInfo["hnsid"] != nil {
  162. container.SharedEndpointList = append(container.SharedEndpointList, gwInfo["hnsid"].(string))
  163. }
  164. }
  165. if data["hnsid"] != nil {
  166. container.SharedEndpointList = append(container.SharedEndpointList, data["hnsid"].(string))
  167. }
  168. }
  169. }
  170. return nil
  171. }