1

in my current directory I have multiple directories that i want to copy them inside dockerfile but not all of them inside single location, lets sya I have dir1, dir2, file1 and i want to copy dir1 into des1 and dir2 into des2 and file1 into WORKDIR . I have no problem doing it with three layes using copy command inside dockerfile, but is there another way to do that in single layer using copy or add command ??

I achieved that by doing this:

COPY dir1/ /app/dir1 COPY dir2/ /app/dir2 COYP file1 /app

Target needed is to do all of them in single COPY.

1 Answers1

0

you could create some sort of script or come up with some clever way to copy src1 dst1 && src2 dst2 but that doesn't help with the final image size (like squashing image layers) or with image pull time (unless you have many many layers and then extracting every little one takes a bit more time).

It's better to separate copying the files to multiple stages so when you change one of them only the changed layer is built again, or when pulling a new verion of the same homebrewed image and only some of the layers have changed and have to be pulled.

some of the sources I've used:

https://github.com/moby/moby/issues/33551

How to copy multiple files in one layer using a Dockerfile?

https://linux.die.net/man/1/cp

Noam Yizraeli
  • 4,446
  • 18
  • 35