How to include files outside of Docker's build context?
Asked 07 September, 2021
Viewed 1.1K times
  • 59
Votes

How can I include files from outside of Docker's build context using the "ADD" command in the Docker file?

From the Docker documentation:


  

The path must be inside the context of the build; you cannot ADD ../something/something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

I do not want to restructure my whole project just to accommodate Docker in this matter. I want to keep all my Docker files in the same sub-directory.

Also, it appears Docker does not yet (and may not ever) support symlinks: Dockerfile ADD command does not follow symlinks on host #1676.

The only other thing I can think of is to include a pre-build step to copy the files into the Docker build context (and configure my version control to ignore those files). Is there a better workaround for than that?

16 Answer