COPY failed: file not found in build context
COPY failed: file not found in build context
DodaTech
2 min read
The error “COPY failed: file not found in build context” means Docker’s COPY instruction in your Dockerfile references a file or directory that does not exist relative to the build context.
What It Means
The COPY instruction in a Dockerfile copies files from the build context (the directory sent to the Docker daemon) into the image. If the source path does not exist within that context, Docker raises this error and the build fails.
Why It Happens
- The source file path is absolute (e.g.,
/home/user/app/config.json) butCOPYonly accepts relative paths. - The file is outside the build context directory but
COPY ../file .is not allowed. - The file was not committed to version control or was deleted before the build.
- The
.dockerignorefile excludes the source file. - The source path is misspelled or the file extension is wrong.
- The build context is a different directory than expected (e.g., running
docker buildfrom the wrong folder).
How to Fix It
1. Check that the file exists relative to the build context
ls -la ./relative/path/to/file2. Ensure COPY uses a relative path
COPY ./app/config.json /app/config.json3. Move the file into the build context
mv /some/other/location/file.txt ./project/4. Check .dockerignore for exclusions
cat .dockerignore5. Build from the correct directory
docker build -t myimage . # "." is the build context6. Use a larger build context if needed
docker build -t myimage -f ./docker/Dockerfile .FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro