This pattern of concatenating commands to have a minimal image is a workaround from times when multi-stage builds were not available.
[0] https://github.com/moby/buildkit/blob/master/frontend/docker...
[1] https://geraldonit.com/2017/11/13/how-to-create-small-docker...
[2] https://docs.docker.com/engine/reference/commandline/image_b...
> I suggest reading about multi-stage builds. They basically squash layers at the end so it's a "have cake and eat it too" scenario.
That's completely different thing. Multi-stage builds are great for separating build environment from production environment, but if you need several layers for production environment, they won't be squashed. See here: https://github.com/docker/compose/issues/4235#issuecomment-3...
Workaround would be to move these files to one directory on host, COPY it in one command to /tmp (or even better, /dev/shm or other ramdisk) and then use script to distribute files where needed.