Is there any way to copy multiple directories in one command, to reduce the number of layers? E.g., instead of:
COPY dirone ./dirone
COPY dirtwo ./dirtwo
COPY dirthree ./dirthree
I want to do:
COPY dirone/ dirtwo/ dirthree/ ./
However, this copies the contents of the directories... but I want to copy the directories themselves.
That's the documented behavior of the copy command:
Best workaround I can suggest is to change your directory layout in your build folder, move the three folders under one parent folder and add the parent.
As BMitch answered, that is expected COPY behaviour.
An alternative would be to
ADD
the contents of a tarball.Create the initial tarball
Add it to the build
The tarball is automatically extracted
Note that every time you update the tar file you are invalidating the Docker build cache for that step. If you are dealing with a lot of files you might want to be smart about when you do the
tar -c
. You could also usetar -u
if you can deal with files not being automatically deleted from the tarball.