Let's say you have your directories tree like this:
dir0
├───dir1
│ └───dir11
| | └───dockerfile
| └───dir12 (current)
└───dir2 (content to be copied)
and your dockerfile look like this:
FROM baseImage
COPY / /content
Let's say you want to copy dir2 content into a new docker image using COPY
or ADD
of dockerfile that is in dir11 and your current directory is dir12
You will have to run this command in order to build your image properly:
docker build -t image-name:tag -f ../dir11/dockerfile ../../dir2
-t your-image-name
Name and optionally a tag in the 'name:tag' format
-f ../dir11/dockerfile
Name of the Dockerfile (Default is 'PATH/Dockerfile')
../../dir2
path to be current for COPY or ADD commands
Update
Let's say you run this by mistake:
docker build -t image-name:tag -f ../dir11/dockerfile ../../
This will not solve your problem because in this case the COPY / /content
will look like it's copying dir0 content (dir1 & dir2) so in order to fix that you can either change the command using the right path or you can also change the COPY source path in the dockerfile like this:
COPY /dir2 /content