Skip to content
Latchkey

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.

docker
ERROR: failed to solve: rpc error: code = Unknown desc = failed to copy: io: read/write on closed pipe

Common 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

  1. This error is usually transient - retry the job once.
  2. If it clears on retry, treat it as a builder/connection blip, not a Dockerfile defect.
Terminal
docker buildx build -t myorg/api:1.4.2 --push .

Free disk space on the builder

  1. Check free space and prune dangling build cache before the build.
  2. A copy that fails every time on a full disk is not transient - reclaim space.
Terminal
df -h /var/lib/docker
docker buildx prune -f

Use a persistent builder instead of a per-job one

  1. Create a long-lived buildx builder so it is not torn down between steps.
  2. Bootstrap it once so the worker is ready before the build.
Terminal
docker buildx create --name ci --driver docker-container --bootstrap --use

How 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.

Frequently asked questions

What causes ""rpc error: failed to copy""?
A buildkitd worker that restarted or lost its connection while streaming a layer leaves the copy half-done.
How do I fix "rpc error: failed to copy"?
Re-run the build

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card