Strange COPY in my dockerfile

Hi,

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 ? :face_with_raised_eyebrow:
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 ?

Thanx again

Please share the output of dir -lR in the folder used as build context.

Thanx for this answer.
Here is is the result.
I removed the user, size and time files :

.:
total 16
myDir
myFile1.txt
myFile2.txt

./myDyr:
total 42140
dirFile1.txt
dirFile2.txt

I edited my first post because I have a clue for the “issue”…thanx and sorry to have been not precise in my first post

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.

I tried it but it doesn’t work either
I found on a post that we must declare the variable as this :

ARG APP_DIR=./myDir

Doesn’t work…

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