docker/cli · error
writing config to tar file for config copy
Error message
writing config to tar file for config copy: %w
What it means
Returned by copyDockerConfigIntoContainer (create.go:420) when io.Copy fails writing the serialized docker config bytes into the in-memory tar.Writer. Because the destination is an in-memory bytes.Buffer, this path is only reached under abnormal conditions (the wrapped %w describes the cause).
Solutions
- Free memory / reduce concurrent container-create load and retry.
- Upgrade the Docker client to a current version in case of a tar writer bug.
- Capture the wrapped underlying error to identify the real cause; this message alone is a symptom.
Defensive patterns
Strategy: retry
Validate before calling
// No meaningful pre-check; both buffers are in-memory. Monitor memory:
import "runtime"
var m runtime.MemStats
runtime.ReadMemStats(&m)
if m.Alloc > maxMem { return errors.New("insufficient memory for config copy") } Try / catch
// Treat as transient/internal; retry once after freeing resources:
if err := createRun(); err != nil && strings.Contains(err.Error(), "writing config to tar") {
runtime.GC(); time.Sleep(backoff); /* retry once */
} Prevention
- Keep Docker CLI current to pick up tar-writer fixes.
- Avoid extreme concurrency in automated create loops.
- Free memory before bulk create operations.
When it happens
Trigger: An internal failure while copying the config buffer into the tar writer during config-copy into the container. Given both source and sink are in-memory buffers, a genuine I/O error here is extremely rare and usually points to a tar.Writer state bug or memory pressure.
Common situations: Rare; typically a symptom of memory exhaustion or a corrupted tar writer state rather than user input. May surface under heavy concurrent create operations or OOM conditions.
Related errors
- closing tar for config copy failed
- saving creds
- copying config.json into container failed
- invalid value: . Valid memory swappiness range is 0-100
- container ID file found, make sure the other container…
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/6fe5874b8a728151.
Report an issue: GitHub.
Appendix: source
Thrown at cli/command/container/create.go:420
// /root/.docker/config.json.
func copyDockerConfigIntoContainer(ctx context.Context, apiClient client.APIClient, containerID string, configPath string, config *configfile.ConfigFile) error {
var configBuf bytes.Buffer
if err := config.SaveToWriter(&configBuf); err != nil {
return fmt.Errorf("saving creds: %w", err)
}
// We don't need to get super fancy with the tar creation.
var tarBuf bytes.Buffer
tarWriter := tar.NewWriter(&tarBuf)
_ = tarWriter.WriteHeader(&tar.Header{
Name: configPath,
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)