Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile, how to COPY files from parent directory

Tags:

docker

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.

like image 999
Tuomas Toivonen Avatar asked May 31 '18 06:05

Tuomas Toivonen


People also ask

Can Dockerfile copy files from parent directory?

It turns out that you cannot include files outside Docker's build context. However, you can copy files from the Dockerfile's parent directory.

How can you tell a Dockerfile to include specific files and directories in a build?

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 .


1 Answers

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.

like image 50
whites11 Avatar answered Oct 03 '22 23:10

whites11