Dockerfile and using ../.. to traverse folder structure outside where dockerfile sits

I have a folder structure where our project uses common projects but those projects do not live under the project that has the dockerfile in it. How can I access the projects outside the dockerfile project to get to those?

I’m trying to use something like

COPY …/…/Common/Encryption/*.csproj ./

This never works.

If you use docker build ., the build context is the current directory. As such it is the correct behavior that you are not allowed to access files in a parent/sibling folder. It would be a security issue if image builds could freely access any files from the host file system.

Let’s assume you have such a structure:

parent
| - folder1
  | - file1
| - folder2
  | - Dockerfile 

You could use COPY folder1/file1 /container/path/file1 if you run docker build --file folder2/Dockerfile . in the parent folder to build the image. The build context would be the parent folder, and folder1/folder1 would be within the build context.