I’m facing a strange thing with a COPY command in my dockerfile.
My local file structure is :
a directory myDir with some files
a file myFile1.txt
a file myFile2.txt
the dockerfile
In my dockerfile I have this command :
COPY myDir /opt/srv/myDir
After the building of my docker image, I start it and go to the /opt/srv directory.
There is the myDir directory BUT the 3 other files too ! myFile1.txt, myFile2.txt and the dockerfile are also in the /opt/srv directory.
I don’t understand why because I don’t have any other COPY command in my dockerfile.
I tried :
COPY myDir/ /opt/srv/myDir
but still the same effect…
What’s wrong ?
Thanx
EDIT :
In fact I used a ARG as this in the top of my dockerfile :
ARG MYDIR=myDir
COPY ${MYDIR} /opt/srv/${MYDIR}
It works if I use myDir instead of ${MYDIR}
How to have the same result using an ARG value ?
I would be surprised if it makes a difference, whether the source path is declared as static string or a variable. I strongly advise using a terminating / character at the end of the target directory, as this will tell the build that it is going to copy a directory.
It should work with docker-ce or docker-desktop from Docker’s own repositories like that. Packages from the os maintainer or snap packages might behave differently.
I remove the ARG definition from the top of my dockerfile and put it under the FROM and now it works…
It was a scope issue apparently…
Thanx for helping me