{"record":{"id":"a9ce3549c9478280","repo":"docker/cli","slug":"closing-tar-for-config-copy-failed-w","errorCode":null,"errorMessage":"closing tar for config copy failed: %w","messagePattern":"closing tar for config copy failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/create.go","lineNumber":424,"sourceCode":"\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":406,"sourceCodeEnd":437,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/create.go#L406-L437","documentation":"Returned by copyDockerConfigIntoContainer (create.go:424) when tar.Writer.Close() fails while finalizing the in-memory tar archive of the docker config. Close flushes the trailing zero blocks of the tar format.","triggerScenarios":"tarWriter.Close() returns an error after writing the config header/body into the in-memory buffer. As with the write step, because the target is a bytes.Buffer, this is an unusual internal failure rather than a typical user error.","commonSituations":"Rare internal failure during tar finalization; usually correlated with the prior io.Copy failing or with a bug in the tar writer under memory pressure.","solutions":["Retry the create after freeing memory/reducing load.","Upgrade the Docker CLI to eliminate a known tar-finalization bug.","Examine the wrapped error for the underlying cause."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// No caller-side pre-check exists; the failure is internal to tar.Close().\n// Best prevention is ensuring a healthy environment: enough memory, current client.\nreturn nil","typeGuard":null,"tryCatchPattern":"// Retry once on this internal error; escalate if it persists.\nif err != nil && strings.Contains(err.Error(), \"closing tar for config copy\") {\n    /* log, free memory, single retry */\n}","preventionTips":["Upgrade the CLI to a patched version.","Reduce concurrent memory pressure during create.","Report persistent occurrences with the wrapped underlying error."],"tags":["container","config","tar","create"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}