Difficulty: Beginner
Estimated Time: 10 minutes

In this scenario you will learn how to use the multi-stage build functionality to make smaller, more optimised images.

The feature is ideal for deploying languages such as Golang as containers. By having multi-stage builds, the first stage can build the Golang binary using a larger Docker image as the base. In the second stage, the newly built binary can be deployed using a much smaller base image. The end result is an optimised Docker Image.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Creating optimised Docker Images using Multi-Stage Builds

Step 1 of 4

Upgrade Docker Master Build

The multi-stage build functionality is currently in the version 17.05 of Docker. Download the binaries and reload the Docker instance to load the latest version.

Download

Download the latest development build from the Docker build server.

curl -L https://master.dockerproject.org/linux/amd64/dockerd-17.05.0-dev -o dockerd mv dockerd /usr/bin/dockerd && chmod +x /usr/bin/dockerd

Restart

Restart to load the new server.

systemctl restart docker

docker version

You can now use the multi-stage build functionality. Note: This is still in beta and not recommended for production.

Dockerfile.multi