Docker: COPY failed: file not found in build context (Dockerfile)

The docker context is the directory the Dockerfile is located in. If you want to build an image that is one of the restrictions you have to face.

In this documentation you can see how contexts can be switched, but to keep it simple just consider the same directory to be the context. Note; this also doesn’t work with symbolic links.

So your observation was correct and you need to place the files you need to copy in the same directory.

Alternatively, if you don’t need to copy them but still have them available at runtime you could opt for a mount. I can imagine this not working in your case because you likely need the files at startup of the container.

Leave a Comment