docker build_error ai_generated true

COPY --from=builder failed: stat /app/build: file not found in build stage

ID: docker/multi-stage-copy-from

Also available as: JSON · Markdown
90%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
27 active

Root Cause

Multi-stage build COPY source path doesn't exist in the builder stage.

generic

Workarounds

  1. 95% success Check the builder stage: the build output path may differ from what you're copying
    # Verify: RUN ls -la /app/build  # add this to builder stage to debug

    Sources: https://docs.docker.com/build/building/multi-stage/

  2. 90% success Ensure the build step in the builder stage actually runs and outputs to the expected path
    # Verify the builder stage output:
    FROM node:20 AS builder
    WORKDIR /app
    COPY . .
    RUN npm ci && npm run build
    # Check: ls -la /app/dist  (this is what COPY --from=builder copies)
    
    FROM node:20-slim
    COPY --from=builder /app/dist ./dist  # Path must match builder output

    Sources: https://docs.docker.com/build/building/multi-stage/

Dead Ends

Common approaches that don't work:

  1. Add the file to the build context 80% fail

    Build context is for COPY without --from; --from copies from another stage

  2. Use a single-stage build 65% fail

    Loses multi-stage benefits (smaller final image, no build tools in prod)

Error Chain

Frequently confused with: