nolint:gocyclo
(ctx context.Context, dockerCLI command.Cli, containerCfg *containerConfig, options *createOptions)
| 212 | |
| 213 | //nolint:gocyclo |
| 214 | func createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *containerConfig, options *createOptions) (containerID string, _ error) { |
| 215 | config := containerCfg.Config |
| 216 | hostConfig := containerCfg.HostConfig |
| 217 | networkingConfig := containerCfg.NetworkingConfig |
| 218 | |
| 219 | var namedRef reference.Named |
| 220 | |
| 221 | // TODO(thaJeztah): add a platform option-type / flag-type. |
| 222 | if options.platform != "" { |
| 223 | if _, err := platforms.Parse(options.platform); err != nil { |
| 224 | return "", err |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | containerIDFile, err := newCIDFile(hostConfig.ContainerIDFile) |
| 229 | if err != nil { |
| 230 | return "", err |
| 231 | } |
| 232 | defer func() { |
| 233 | _ = containerIDFile.Close() |
| 234 | }() |
| 235 | |
| 236 | ref, err := reference.ParseAnyReference(config.Image) |
| 237 | if err != nil { |
| 238 | return "", err |
| 239 | } |
| 240 | if named, ok := ref.(reference.Named); ok { |
| 241 | namedRef = reference.TagNameOnly(named) |
| 242 | } |
| 243 | |
| 244 | const dockerConfigPathInContainer = "/run/secrets/docker/config.json" |
| 245 | var apiSocketCreds map[string]types.AuthConfig |
| 246 | |
| 247 | if options.useAPISocket { |
| 248 | // We'll create two new mounts to handle this flag: |
| 249 | // |
| 250 | // 1. Mount the actual docker socket. |
| 251 | // 2. A synthesized ~/.docker/config.json with resolved tokens. |
| 252 | |
| 253 | if dockerCLI.ServerInfo().OSType == "windows" { |
| 254 | return "", errors.New("flag --use-api-socket can't be used with a Windows Docker Engine") |
| 255 | } |
| 256 | |
| 257 | // hard-code engine socket path until https://github.com/moby/moby/pull/43459 gives us a discovery mechanism |
| 258 | containerCfg.HostConfig.Mounts = append(containerCfg.HostConfig.Mounts, mount.Mount{ |
| 259 | Type: mount.TypeBind, |
| 260 | Source: "/var/run/docker.sock", |
| 261 | Target: "/var/run/docker.sock", |
| 262 | BindOptions: &mount.BindOptions{}, |
| 263 | }) |
| 264 | |
| 265 | /* |
| 266 | |
| 267 | Ideally, we'd like to copy the config into a tmpfs but unfortunately, |
| 268 | the mounts won't be in place until we start the container. This can |
| 269 | leave around the config if the container doesn't get deleted. |
| 270 | |
| 271 | We are using the most compose-secret-compatible approach, |
searching dependent graphs…