Multistage container builds
We have learned so far how to create builds with Podman and Buildah using Dockerfiles or native Buildah commands that unleash potential advanced building techniques.
There is still an important point that we haven't already discussed – the size of the images.
When creating a new image, we should always take care of its final size, which is the result of the total number of layers and the number of changed files inside them.
Minimal images with a small size have the great advantage of being able to be pulled faster from registries. Nevertheless, a large image will eat a lot of precious disk space in the host's local store.
We already showed examples of some best practices to keep images compact in size, such as building from scratch, cleaning up package manager caches, and reducing the amount of RUN
, COPY
, and ADD
instructions to the minimum necessary. However, what happens when we need to build an application from its source...