container_operations_windows.go 5.8 KB

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