DEV Community

Discussion on: Why you should use Multi Stage Docker Builds

Collapse
 
nfrankel profile image
Nicolas Frankel
  1. Yes, you should do multi-stage builds.
  2. Yes, size does matter, but much less than what you'd think

Remember that Docker images are layered. It doesn't play a role when you start FROM scratch but people very rarely do create standalone binaries.

In general, they start from an platform, e.g., a Java Runtime Environment, the latest Node.js, etc. In that case, the platform takes the bulk of the image's size, i.e., the app itself is very small compared to the platform.

Now comes the important part: Docker doesn't cache images but layers. Hence, if your new dockerized app version uses the same parent layer, only your app layer is downloaded.

For that reason, it's much better to focus on your order layers than on size. By pointing readers to the wrong problem, they will probably come up with the wrong solution (squash).