{"record":{"id":"6fe5874b8a728151","repo":"docker/cli","slug":"writing-config-to-tar-file-for-config-copy-w","errorCode":null,"errorMessage":"writing config to tar file for config copy: %w","messagePattern":"writing config to tar file for config copy: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/create.go","lineNumber":420,"sourceCode":"// /root/.docker/config.json.\nfunc copyDockerConfigIntoContainer(ctx context.Context, apiClient client.APIClient, containerID string, configPath string, config *configfile.ConfigFile) error {\n\tvar configBuf bytes.Buffer\n\tif err := config.SaveToWriter(&configBuf); err != nil {\n\t\treturn fmt.Errorf(\"saving creds: %w\", err)\n\t}\n\n\t// We don't need to get super fancy with the tar creation.\n\tvar tarBuf bytes.Buffer\n\ttarWriter := tar.NewWriter(&tarBuf)\n\t_ = tarWriter.WriteHeader(&tar.Header{\n\t\tName: configPath,\n\t\tSize: int64(configBuf.Len()),\n\t\tMode: 0o600,\n\t})\n\n\tif _, err := io.Copy(tarWriter, &configBuf); err != nil {\n\t\t_ = tarWriter.Close()\n\t\treturn fmt.Errorf(\"writing config to tar file for config copy: %w\", err)\n\t}\n\n\tif err := tarWriter.Close(); err != nil {\n\t\treturn fmt.Errorf(\"closing tar for config copy failed: %w\", err)\n\t}\n\n\t_, err := apiClient.CopyToContainer(ctx, containerID, client.CopyToContainerOptions{\n\t\tDestinationPath: \"/\",\n\t\tContent:         &tarBuf,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"copying config.json into container failed: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":402,"sourceCodeEnd":437,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/create.go#L402-L437","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// No meaningful pre-check; both buffers are in-memory. Monitor memory:\nimport \"runtime\"\nvar m runtime.MemStats\nruntime.ReadMemStats(&m)\nif m.Alloc > maxMem { return errors.New(\"insufficient memory for config copy\") }","typeGuard":null,"tryCatchPattern":"// Treat as transient/internal; retry once after freeing resources:\nif err := createRun(); err != nil && strings.Contains(err.Error(), \"writing config to tar\") {\n    runtime.GC(); time.Sleep(backoff); /* retry once */\n}","preventionTips":["Keep Docker CLI current to pick up tar-writer fixes.","Avoid extreme concurrency in automated create loops.","Free memory before bulk create operations."],"tags":["container","config","tar","memory","create"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}