I have folder with files common for multiple docker images. How can I COPY
these files to the image referencing the parent directory in Dockerfile? Obviously I don't want to duplicate this folder to all Docker projects.
It turns out that you cannot include files outside Docker's build context. However, you can copy files from the Dockerfile's parent directory.
The best way to work around this is to specify the Dockerfile independently of the build context, using -f. For instance, this command will give the ADD command access to anything in your current directory. docker build -f docker-files/Dockerfile . docker build -f ../Dockerfile .
When you run docker build
the latest parameter is called PATH
. Here is a description of it taken from here:
The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH [omissis]. The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.
That means you have to specify a PATH
that contains all of the files you need in your Dockerfile. Please be aware that changing the PATH
to a different directory will require changing all of your COPY
and ADD
instructions to reflect the new directory structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With