Docker "failed to solve: rpc error: code = Unknown desc = failed to copy" in CI
BuildKit moves layer data over an internal RPC stream. When that stream is interrupted mid-transfer - a builder that was torn down, a dropped connection, or an I/O stall - the copy never finishes and the solve fails with rpc error: code = Unknown desc = failed to copy. This is usually a transient infrastructure hiccup rather than a Dockerfile bug.
What this error means
A docker buildx build fails partway through with failed to solve: rpc error: code = Unknown desc = failed to copy, often while exporting or transferring a layer. A re-run frequently succeeds.
ERROR: failed to solve: rpc error: code = Unknown desc = failed to copy: io: read/write on closed pipeCommon causes
The builder connection dropped mid-transfer
A buildkitd worker that restarted or lost its connection while streaming a layer leaves the copy half-done.
An I/O stall or disk pressure on the builder
A slow or full disk on the build host can stall the layer write long enough for the RPC to give up.
A torn-down ephemeral builder
When a CI runner or remote builder is recycled while a build is in flight, the in-progress copy is killed.
How to fix it
Re-run the build
- This error is usually transient - retry the job once.
- If it clears on retry, treat it as a builder/connection blip, not a Dockerfile defect.
docker buildx build -t myorg/api:1.4.2 --push .Free disk space on the builder
- Check free space and prune dangling build cache before the build.
- A copy that fails every time on a full disk is not transient - reclaim space.
df -h /var/lib/docker
docker buildx prune -fUse a persistent builder instead of a per-job one
- Create a long-lived buildx builder so it is not torn down between steps.
- Bootstrap it once so the worker is ready before the build.
docker buildx create --name ci --driver docker-container --bootstrap --useHow to prevent it
- Keep build-host disks below capacity so layer writes do not stall.
- Use a persistent builder rather than recreating one per job.
- Retry transient copy failures before investigating the Dockerfile.