docker build ai_generated true

COPY failed: file not found in build context

ID: docker/copy-failed-stat

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
24 active
27 active

Root Cause

COPY instruction references a file that doesn't exist in the Docker build context.

generic

Workarounds

  1. 93% success Check .dockerignore — the file may exist but be ignored during context transfer
    Remove the file pattern from .dockerignore

    Sources: https://docs.docker.com/build/building/context/#dockerignore-files

  2. 95% success Verify the file path is relative to the build context (the directory passed to docker build)
    docker build -f Dockerfile . — the '.' is the build context root

Dead Ends

Common approaches that don't work:

  1. Using absolute host paths in COPY 90% fail

    Docker COPY only works within the build context; absolute paths are forbidden

  2. Using volume mounts during build 85% fail

    docker build doesn't support volumes; only RUN, COPY, ADD work

Error Chain

Frequently confused with: