{"record":{"id":"c952a3e30a31ca9e","repo":"docker/cli","slug":"copying-config-json-into-container-failed-w","errorCode":null,"errorMessage":"copying config.json into container failed: %w","messagePattern":"copying config\\.json into container failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/create.go","lineNumber":432,"sourceCode":"\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":414,"sourceCodeEnd":437,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/create.go#L414-L437","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the container still exists: docker ps -a --filter id=<id>.","Check daemon connectivity and that DOCKER_HOST/TLS config is correct.","Increase timeout / ensure the context is not cancelled prematurely.","Retry the create; transient transport errors often resolve."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Verify container exists and daemon is reachable before copying:\nctx := context.Background()\nif _, err := cli.ContainerInspect(ctx, id); err != nil {\n    return fmt.Errorf(\"container not ready for config copy: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Retry transient transport errors with backoff; fail fast on NotFound:\nif err := cli.CopyToContainer(ctx, id, \"/\", buf, types.CopyToContainerOptions{}); err != nil {\n    if isNotFound(err) { return err }            // permanent\n    backoff.Retry(doCopy, backoff.NewExponentialBackOff())\n}","preventionTips":["Confirm DOCKER_HOST/TLS context before create.","Use a context with adequate timeout for large configs.","Guard against removing the container mid-create."],"tags":["container","config","daemon","network","copy","create"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}