Use Multi-Stage Builds to Improve Continuous Delivery Pipeline
Learn how to use Docker multi-stage builds
Introduction
A basic rule for building a container image is “the smaller is better”.
But it’s not an easy job for the compiled language (e.g. go, java) due to large build environment and dependencies. In the post “Building Minimal Docker Image for Go Applications”, we need to produce a go binary first and put it into scratch
image. And it’s quite complicated and heavy for developers to create such continuous delivery pipeline.
To solve this problem, Docker 17.05+ releases a new feature called Multi-stage builds
. With this feature we can combine multiple dockerfiles into one and let base image to copy artifacts and outputs from the intermediate image. In this way, we can keep pipeline easy to read and maintain.