Create your FREE Codefresh account and start making pipelines fast. Create Account

Webinar: Using Docker Multi-stage Build to Create Advanced Pipelines

2 min read

One of the biggest announcements at DockerCon 2017 was the launch of Multi-stage Builds. It’s available in Docker version 17.05 onwards and is one of most exciting features to come out. In our last webinar, we demonstrated how to use the new Docker Multi-stage Build feature to create advanced pipelines using a single Dockerfile.

View the webinar on-demand to learn:

  • What’s need for a Docker build pipeline
  • Existing solutions
  • New Dockerfile syntax for Multi-stage Builds
  • Demo: How to use the Multi-stage Build feature

Link to Alexei’s slides

Webinar Highlights:

Docker Build

  • Dockerfile – imperative DSL that defines build commands
  • Each docker build command generates ONE image layer
  • Complete docker build execution generates ONE Docker image

Problem with Docker Build

When we create a new image we want to include the basic runtime, some configuration, and the application itself. However,  we often build our image with additional tools/ packages, such as compilers, debuggers, test frameworks, profilers, build artifacts, etc. We end up with an image that’s 4-10x bigger than we need to run our application.


Docker Builder Pattern

  • 2 Dockerfiles
    • 1st for build tools
    • 2nd for runtime
  • Drawbacks:

    • Need 2+ Dockerfiles
    • Orchestration needed (need to learn additional tools like BASH, Make, YAML and it’s not always easy to reproduce on local machine)

Docker Version 17.05

Docker introduced multi-stage builds in their latest release. It allows you to build smaller images, and separate build into stages. For example, in the first stage you can create the complete build environment and in the second stage, create the minimal runtime environment using a single Dockerfile.

  • Benefits:

    • One Dockerfile
    • One syntax to learn
    • Same build
    • Works on Local machine and CI server
    • Can create multiple stages

Here is an example to illustrate how this is done:


Node.js Multistage Build

(See demo – 14 minutes  20 seconds of the webinar)

In the demo, Alexei showed how to create a lean Node.js image using the following demo chat application. (You’ll need to get Docker v17.05 to try Docker multi-stage build.)

Go Multistage Build

(See demo – 22 minutes  20 seconds of the webinar)

In another example, Alexei showed how to create a Go Multi-stage build using the following open-source project called Pumba. 

Use Multi-stage builds Codefresh

Currently, Codefresh is the only CI that supports Docker Multi-stage builds. You can try it for free using your private or public repo. For more information on how to use this feature, check out this blog post.

Additional Resources

Dan Garfield

Dan is the Co-Founder and Chief Open Source Officer at Codefresh. His work in open source includes being an Argo Maintainer, and co-chair of the GitOps Working Group. As a technology leader with a background in full-stack engineering, evangelism, and communications, he led Codefresh's go-to-market strategy and now leads open source strategy. You can follow him at

Leave a Reply

* All fields are required. Your email address will not be published.