container_operations_windows.go 5.7 KB

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