ProjectStack
docker

COPY failed: file not found in build context or excluded by .dockerignore: stat X: file does not exist

A COPY or ADD instruction in your Dockerfile references a file or directory that Docker can't find. Docker only has access to files within the build context — the directory you pass to docker build — so paths outside it or files excluded by .dockerignore don't exist from Docker's perspective.

Common causes

  • The file path in COPY is wrong — check relative to the build context, not the Dockerfile location
  • The file is listed in .dockerignore and is being excluded from the build context
  • You're running docker build from the wrong directory so the file isn't in the context
  • The file genuinely doesn't exist and needs to be created before building

How to fix it

  1. Verify the file exists and the path is correct relative to where you run docker build
  2. Check your .dockerignore — if it excludes the file, remove that exclusion or adjust the pattern
  3. Run docker build from the project root: docker build -t myapp . (where . includes the needed files)
  4. Use a specific build context: docker build -t myapp -f path/to/Dockerfile path/to/context

Example

$ docker build -t myapp . COPY failed: file not found in build context or excluded by .dockerignore: stat config/settings.json: file does not exist

COPY instruction references config/settings.json but the file doesn't exist in the build context

Browse more errors

The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.