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