5 ms·
Using build stages is usually the biggest contributor to reduction in image size. Usually, images have steps to build (which requires source code, dependencies
by CraftThatBlock 5y ago
Using build stages is usually the biggest contributor to reduction in image size.
Usually, images have steps to build (which requires source code, dependencies, etc), and the entry point at the end. Splitting the build- and run-time means you're shipping an image that only includes what's needed to run (not build) the application.
- Gigachad 5y agoYou can resolve this by installing, building, and uninstalling in the same RUN command right? I once worked at a place that used some insane setup with images building other images to avoid this but I'm pretty sure the first option works as well.
- Harvesterify 5y agoYou could, but the biggest benefit of staged builds (IMHO) is that you can use a heavy base image for the build process (classic Ubuntu for example, where it's easy to add repositories and install dependencies), and a very small image for runtime (i.e. Alpine, busybox). I find that it's easier to debug the build process with a "standard" distribution.
- CraftThatBlock 5y agoTechnically, yes, but it's much easier to use Dockerfiles like normal (and have the build step is a good environment for development), and copy exactly the files you need for the release stage.