For my first real post of my new blog, let’s talk about multi-stage docker
builds. This blog is built with the aid of just such a build. A multi-stage docker
build gives you the ability to build multiple containers. In the case of my
build, it helps me build a single end-product that’s uncluttered by extra
build configuration and tooling.
Why multi-stage?
Docker holds a place in the modern development pipeline for deployed
applications similar to the role the classic Makefile has in building packaged
applications. (There’s a reason the Dockerfile and Makefile use a similar
nomenclature after all.) However, when building a deployed application, you
often need to perform build tasks that create clutter. For example, if you’re
building a C program, you’ll like need to install the build tools (sudo apt-get install build-essential) and then when you run make you get all those
intermediate .o files needed for linking, and maybe you need to install Perl or
Python to help run some of the glue code, etc.