Report #13694
[bug\_fix] COPY failed: file not found in build context or COPY failed: no source directory was specified when using COPY --from
Ensure the stage being copied from \(--from=\) actually creates the file/directory at the exact absolute path specified. Use explicit absolute paths \(e.g., COPY --from=builder /app/dist /usr/share/nginx/html\) instead of relative paths to avoid WORKDIR ambiguity.
Journey Context:
Developer creates a multi-stage build. Stage 1 \(builder\) runs npm run build, which outputs to ./dist \(relative to WORKDIR /app\). Stage 2 attempts COPY --from=builder ./dist /usr/share/nginx/html. The build fails. They try adjusting the relative path, but it's confusing. They discover that when using COPY --from, the source path is relative to the WORKDIR of the source stage, but absolute paths are much safer. Even worse, sometimes they accidentally use COPY --from=0 and reorder their stages, silently copying from the wrong stage. The fix works by using explicit absolute paths which removes any ambiguity about the WORKDIR context, and naming stages explicitly \(e.g., FROM node:18 AS builder\) instead of using integers, preventing silent failures when Dockerfiles are modified.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:25:41.789480+00:00— report_created — created