MCPcopy Index your code
hub / github.com/docker/cli / copyDockerConfigIntoContainer

Function copyDockerConfigIntoContainer

cli/command/container/create.go:403–436  ·  view source on GitHub ↗

copyDockerConfigIntoContainer takes the client configuration and copies it into the container. The path should be an absolute path in the container, commonly root/.docker/config.json.

(ctx context.Context, apiClient client.APIClient, containerID string, configPath string, config *configfile.ConfigFile)

Source from the content-addressed store, hash-verified

401// The path should be an absolute path in the container, commonly
402// /root/.docker/config.json.
403func copyDockerConfigIntoContainer(ctx context.Context, apiClient client.APIClient, containerID string, configPath string, config *configfile.ConfigFile) error {
404 var configBuf bytes.Buffer
405 if err := config.SaveToWriter(&configBuf); err != nil {
406 return fmt.Errorf("saving creds: %w", err)
407 }
408
409 // We don't need to get super fancy with the tar creation.
410 var tarBuf bytes.Buffer
411 tarWriter := tar.NewWriter(&tarBuf)
412 _ = tarWriter.WriteHeader(&tar.Header{
413 Name: configPath,
414 Size: int64(configBuf.Len()),
415 Mode: 0o600,
416 })
417
418 if _, err := io.Copy(tarWriter, &configBuf); err != nil {
419 _ = tarWriter.Close()
420 return fmt.Errorf("writing config to tar file for config copy: %w", err)
421 }
422
423 if err := tarWriter.Close(); err != nil {
424 return fmt.Errorf("closing tar for config copy failed: %w", err)
425 }
426
427 _, err := apiClient.CopyToContainer(ctx, containerID, client.CopyToContainerOptions{
428 DestinationPath: "/",
429 Content: &tarBuf,
430 })
431 if err != nil {
432 return fmt.Errorf("copying config.json into container failed: %w", err)
433 }
434
435 return nil
436}

Callers 1

createContainerFunction · 0.85

Calls 4

SaveToWriterMethod · 0.80
CopyToContainerMethod · 0.80
LenMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…