How to squash Dockerfiles?
Assume I have a hierarchy of images, one inheriting from the other with FROM:
- B: FROM A
- C: FROM B
- D: FROM C
A is a standard base image, and B,C,D are my own images.
Now I need to create a Dockerfile for D’, with same additions coming from Dockerfiles of B, C and D, but based on a different base image – A’.
I can think of a couple of ways to achieve this:
- Create dockerfile for B’, identical to B but inheriting from A’. Same for C’ and D’.
- Create a completely new Dockerfile for D’, with base image A’ and copy-pasting all the commands from dockerfiles of B, C and D.
Is there a better way to achieve this? I guess a tool/scrtipt that would do #2 might be enough.