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