Thoughts:
-
each line in the Dockerfile can be considered a cache-layer. If something changes and causes a layer to require rebuild, all following layers need a rebuild too.
-
structure the file so that more-expensive-and-less-likely-to-change things are as close to the top of the file as possible.
-
think about scenarios where things do change, and look at which expensive layers are invalidated.
-
say we have 2 costly (time-consuming) layers, A and B.
- in scenario 1, only A needs to be rebuilt
- in scenario 2, only B needs to be rebuilt
-
the problem here is that no matter which way you order it, you always end up doing some unnecessary rebuilding. (check: is this assumption correct?!)
-
it might be possible in this situation to improve by splitting A and B into 2 separate Dockerfiles