Oh, what are the advantages of doing that in a different container as opposed to a different layer? Trying to understand the pros/cons..
Isn't it faster to add extra layers, than extra containers?
This is the builder pattern in docker. You do things in one "throw away" container, use results from this container and copy them into another. The final container gets only one layer now, instead of maybe 10s that your "throw away" container had.
Layers are add only. If you removea file, it still exists in the parent layer, propagating bloat
Different layer means you have to carry around that layer in your final image. If you do a multi-stage build, you can copy over just the bits you need into the final image.