12

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.

Tuomas Toivonen
  • 21,690
  • 47
  • 129
  • 225
  • 4
    Possible duplicate of [Docker: adding a file from a parent directory](https://stackoverflow.com/questions/24537340/docker-adding-a-file-from-a-parent-directory) – dds Aug 29 '18 at 18:22
  • 3
    execute `build` from parent directory, using the `--file` flag. then `COPY` will have visibility into the sibling folders. see https://stackoverflow.com/a/34300129/3029276. – ellemenno Jan 20 '21 at 21:20

1 Answers1

3

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.

whites11
  • 12,008
  • 3
  • 36
  • 53