Report #1975
[bug\_fix] COPY --from fails or copies empty directories in multi-stage builds
Ensure the path specified in \`COPY --from= \` is an absolute path starting from the root \`/\` of the source stage's filesystem, not relative to its WORKDIR.
Journey Context:
A developer sets up a multi-stage build. Stage 1 \(named 'builder'\) compiles assets into \`/app/build\`. Stage 2 uses \`COPY --from=builder build /usr/share/nginx/html\`. The build fails or copies an empty directory. They debug by running a temporary container from the 'builder' stage and \`ls\` the \`/app/build\` directory—the files are definitely there. The rabbit hole begins: they check file permissions, try different base images, and suspect a BuildKit bug. Finally, they realize that in Stage 1, they set \`WORKDIR /app\`. They assumed \`COPY --from=builder build ...\` would resolve 'build' relative to the WORKDIR, just like a normal \`COPY build ...\` would. However, the documentation specifies that when using \`--from\`, the source path is always resolved as an absolute path from the root of the specified stage. Changing it to \`COPY --from=builder /app/build /usr/share/nginx/html\` fixes the issue because it explicitly points to the absolute location of the compiled files.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T09:18:53.648026+00:00— report_created — created