docker/cli · error

copying config.json into container failed

Error message

copying config.json into container failed: %w

What it means

Returned by copyDockerConfigIntoContainer (create.go:432) when the SDK call apiClient.CopyToContainer fails. This is the actual networked call that streams the prepared config.json tarball into the running container at /. The wrapped %w carries the daemon-side or transport error.

Solutions

  1. Verify the container still exists: docker ps -a --filter id=<id>.
  2. Check daemon connectivity and that DOCKER_HOST/TLS config is correct.
  3. Increase timeout / ensure the context is not cancelled prematurely.
  4. Retry the create; transient transport errors often resolve.
Defensive patterns

Strategy: retry

Validate before calling

// Verify container exists and daemon is reachable before copying:
ctx := context.Background()
if _, err := cli.ContainerInspect(ctx, id); err != nil {
    return fmt.Errorf("container not ready for config copy: %w", err)
}

Try / catch

// Retry transient transport errors with backoff; fail fast on NotFound:
if err := cli.CopyToContainer(ctx, id, "/", buf, types.CopyToContainerOptions{}); err != nil {
    if isNotFound(err) { return err }            // permanent
    backoff.Retry(doCopy, backoff.NewExponentialBackOff())
}

Prevention

When it happens

Trigger: The container has been created but CopyToContainer fails: the container ID does not exist (already removed), the daemon refused the copy, the destination path / is invalid, a network/transport error occurred, or the context was cancelled.

Common situations: Container was removed between create and copy, daemon restart mid-operation, TLS/permission issues against a remote daemon, or a cancelled/timeout context during a slow copy.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/c952a3e30a31ca9e. Report an issue: GitHub.

Appendix: source

Thrown at cli/command/container/create.go:432

		Size: int64(configBuf.Len()),
		Mode: 0o600,
	})

	if _, err := io.Copy(tarWriter, &configBuf); err != nil {
		_ = tarWriter.Close()
		return fmt.Errorf("writing config to tar file for config copy: %w", err)
	}

	if err := tarWriter.Close(); err != nil {
		return fmt.Errorf("closing tar for config copy failed: %w", err)
	}

	_, err := apiClient.CopyToContainer(ctx, containerID, client.CopyToContainerOptions{
		DestinationPath: "/",
		Content:         &tarBuf,
	})
	if err != nil {
		return fmt.Errorf("copying config.json into container failed: %w", err)
	}

	return nil
}

View on GitHub (pinned to 4f84911bfe)