SlideShare a Scribd company logo
Why you should be using Multi-Stage
Docker Builds in 2019
GUY SALTON
Guy
Salton
Solutions Architect
guy.salton@codefresh.io
Agenda
● The problem with Docker build
● Solution: Docker multi-stage build
● Docker multi-stage build in CI/CD
● Summary
● Dockerfile and Docker build
https://github.com/codefresh-contrib/golang-sample-app/
https://codefresh.io/docs/docs/learn-by-example/golang/golang-hello-world/
Docker multi-stage build
● “oh man! thank you! I've been fighting with build times on an image stack for weeks”
● “Wow, this is great for deploying tonnes of microservices!”
● “I've been meaning to use multistage builds, thanks for the walkthrough!”
https://www.reddit.com/r/golang/comments/crkibq/docker_golang_reducing_container_size_using/
Multi-stage build is available starting from Docker 17.05 (released in 2017!) - so why now?
Dockerfile and 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
Dockerfile and Docker build
Demo 1:
Docker build on GO app
https://github.com/codefresh-contrib/helm-sample-app
The Problem with Docker build
Image we want Image we build
runtime
configuration
application
Compilers, debuggers, ...
Linters, tests, profilers, ...
code, build and test logs, ...
runtime
configuration
application
X (4..10)
The Problem with Docker build
● 2 Dockerfiles
○ 1st for build tools
○ 2nd for runtime
● Drawbacks
○ 2+ Dockerfiles
○ Orchestration needed: Bash, make, YAML, ...
Solution: Docker multi-stage build
● Benefits
○ One Dockerfile
○ One syntax to learn
○ Same build
■ Local and CI
○ Create multiple stages
guy.salton@codefresh.io
FROM: alpine:3.5
curl
FROM: ubuntu
/hello
FROM: debian
/world
FROM: base
/hello
/world
Demo 2:
Docker multi-stage build
Docker multi-stage build
You can enjoy multi-stage build with every programming language (not only GO):
● GO example - https://codefresh.io/docs/docs/learn-by-example/golang/golang-hello-world/#create-a-multi-stage-docker-image-for-go
● JAVA example - https://codefresh.io/docs/docs/learn-by-example/java/spring-boot-2/#spring-boot-2-and-docker-multi-stage-builds
● Node example - https://codefresh.io/docs/docs/learn-by-example/nodejs/react/#react-and-docker-multi-stage-builds
● PHP example - https://codefresh.io/docs/docs/learn-by-example/php/#the-example-php-project
https://codefresh.io/containers/docker-anti-patterns/Docker anti-patterns
Codefresh
The 1st container-native
CI/CD Platform for
Microservices
Container-native
Intuitive & Robust
Enterprise Ready
Flexible Delivery
Demo 3:
Docker multi-stage build in CI/CD
Summary
● Using 1 Docker image for both build and
production results in slow deployment and
lots of CVE violations
● Multi-stage build to produce lean, secure
and production ready Docker image
● On Codefresh, speedier builds thanks to
caching across all images and layers
Signup for a FREE account with
UNLIMITED builds
& schedule a 1:1 with
our experts at
https://codefresh.io
Build Fast,
Deploy Faster
Thank You!
guy.salton@codefresh.io

More Related Content

What's hot (20)

PDF
Deploying containerized applications with Kubeapps
Janakiram MSV
 
PDF
CRI, OCI, and CRI-O
Che-Chia Chang
 
PPTX
Automate The Creation/Transformation of Infrastructure as Code Artifacts with...
Konveyor Community
 
PPTX
How to Modernize Virtualized Workloads
Konveyor Community
 
PPTX
Microservice Development Using Telepresence
Vishal Banthia
 
PPTX
Continuous Delivery to Kubernetes Using Helm
Adnan Abdulhussein
 
PPTX
[Konveyor] adding security to dev ops for your kubernetes native applications
Konveyor Community
 
PDF
Thinking One Step Further with Time-saving DevOps Tools with Open Telekom Clo...
Bitnami
 
PPTX
Docker 1.5 features - South Bay Microservices meetup March 2015
Ritesh Patel
 
PPTX
Versioning in Pipeline Pilot - Pipeline Pilot Forum 2018
Peter Schmidtke
 
PPTX
From development to production: Deploying Java and Scala apps to kubernetes
Olanga Ochieng'
 
PDF
Dr. Strangeconfig or: How I Learned to Stop Using Chef and Puppet and Love th...
Amir Moghimi
 
PPTX
Migrating Java JBoss EAP Applications to Kubernetes With S2I
Konveyor Community
 
PPTX
Cost Control and Rapid Innovation in Kubernetes with OpenRewrite
Konveyor Community
 
PDF
Kubernetes buildpacks - from a source code to the running OCI container with ...
PROIDEA
 
PPTX
A mini adventure in Minikube devopsdays CT 2017
Whitney Tennant
 
PDF
Paris Container Day 2016 : Deep dive dc-os ci-cd (Mesosphere & Container Solu...
Publicis Sapient Engineering
 
PPTX
An Introduction to Docker
bwinterton
 
PDF
Cicd pixelfederation
Juraj Hantak
 
PDF
Containers and Orchestration approaches
kloia
 
Deploying containerized applications with Kubeapps
Janakiram MSV
 
CRI, OCI, and CRI-O
Che-Chia Chang
 
Automate The Creation/Transformation of Infrastructure as Code Artifacts with...
Konveyor Community
 
How to Modernize Virtualized Workloads
Konveyor Community
 
Microservice Development Using Telepresence
Vishal Banthia
 
Continuous Delivery to Kubernetes Using Helm
Adnan Abdulhussein
 
[Konveyor] adding security to dev ops for your kubernetes native applications
Konveyor Community
 
Thinking One Step Further with Time-saving DevOps Tools with Open Telekom Clo...
Bitnami
 
Docker 1.5 features - South Bay Microservices meetup March 2015
Ritesh Patel
 
Versioning in Pipeline Pilot - Pipeline Pilot Forum 2018
Peter Schmidtke
 
From development to production: Deploying Java and Scala apps to kubernetes
Olanga Ochieng'
 
Dr. Strangeconfig or: How I Learned to Stop Using Chef and Puppet and Love th...
Amir Moghimi
 
Migrating Java JBoss EAP Applications to Kubernetes With S2I
Konveyor Community
 
Cost Control and Rapid Innovation in Kubernetes with OpenRewrite
Konveyor Community
 
Kubernetes buildpacks - from a source code to the running OCI container with ...
PROIDEA
 
A mini adventure in Minikube devopsdays CT 2017
Whitney Tennant
 
Paris Container Day 2016 : Deep dive dc-os ci-cd (Mesosphere & Container Solu...
Publicis Sapient Engineering
 
An Introduction to Docker
bwinterton
 
Cicd pixelfederation
Juraj Hantak
 
Containers and Orchestration approaches
kloia
 

Similar to Why You Should be Using Multi-stage Docker Builds in 2019 (20)

PDF
Docker based-pipelines
DevOps.com
 
PDF
Docker based-Pipelines with Codefresh
Codefresh
 
PDF
Docker in everyday development
Justyna Ilczuk
 
PPTX
Docker Timisoara: Dockercon19 recap slides, 23 may 2019
Radulescu Adina-Valentina
 
PPTX
Настройка окружения для кросскомпиляции проектов на основе docker'a
corehard_by
 
PDF
A Gentle Introduction to Docker and Containers
Docker, Inc.
 
PDF
Build and run applications in a dockerless kubernetes world
Jorge Morales
 
PDF
Adventures in docker compose
LinkMe Srl
 
PDF
AllTheTalks 2020: Buildpacks - container for everyone!
Zander Mackie
 
PPTX
Introduction to Docker Compose
Prabhas Gupte
 
PDF
Introduction to Docker and Containers
Docker, Inc.
 
ODP
Boston Ruby Group - Devops Pipeline
Michael Durrant
 
PDF
Docker for local development
Adam Štipák
 
PDF
VM vs Docker-Based Pipelines
Codefresh
 
PPTX
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
DevOps.com
 
ODP
DevAssistant, Docker and You
BalaBit
 
PPTX
Multi-stage Docker builds to make building easy!
Milindu Sanoj Kumarage
 
PDF
Perspectives on Docker
RightScale
 
PDF
Real-World Docker: 10 Things We've Learned
RightScale
 
PPTX
Getting started with docker (2017)
JEMLI Fathi
 
Docker based-pipelines
DevOps.com
 
Docker based-Pipelines with Codefresh
Codefresh
 
Docker in everyday development
Justyna Ilczuk
 
Docker Timisoara: Dockercon19 recap slides, 23 may 2019
Radulescu Adina-Valentina
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
corehard_by
 
A Gentle Introduction to Docker and Containers
Docker, Inc.
 
Build and run applications in a dockerless kubernetes world
Jorge Morales
 
Adventures in docker compose
LinkMe Srl
 
AllTheTalks 2020: Buildpacks - container for everyone!
Zander Mackie
 
Introduction to Docker Compose
Prabhas Gupte
 
Introduction to Docker and Containers
Docker, Inc.
 
Boston Ruby Group - Devops Pipeline
Michael Durrant
 
Docker for local development
Adam Štipák
 
VM vs Docker-Based Pipelines
Codefresh
 
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
DevOps.com
 
DevAssistant, Docker and You
BalaBit
 
Multi-stage Docker builds to make building easy!
Milindu Sanoj Kumarage
 
Perspectives on Docker
RightScale
 
Real-World Docker: 10 Things We've Learned
RightScale
 
Getting started with docker (2017)
JEMLI Fathi
 
Ad

More from Codefresh (20)

PDF
Detect, debug, deploy with Codefresh and Lightstep
Codefresh
 
PDF
Simplify Your Code with Helmfile
Codefresh
 
PDF
5 Simple Tips for Troubleshooting Your Kubernetes Pods
Codefresh
 
PPTX
Deploy Secure Cloud-Native Apps Fast
Codefresh
 
PDF
Codefresh CICD New Features Launch! May 2019
Codefresh
 
PDF
Terraform GitOps on Codefresh
Codefresh
 
PDF
Adding Container Image Scanning to Your Codefresh Pipelines with Anchore
Codefresh
 
PDF
Image scanning using Clair
Codefresh
 
PDF
Updating Kubernetes With Helm Charts: Build, Test, Deploy with Codefresh and...
Codefresh
 
PDF
Automated Serverless Pipelines with #GitOps on Codefresh
Codefresh
 
PDF
Discovering and Fixing Dependency Vulnerabilities for Kubernetes apps with Sn...
Codefresh
 
PDF
Net Pipeline on Windows Kubernetes
Codefresh
 
PPTX
Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh
Codefresh
 
PPTX
Skip Staging! Test Docker, Helm, and Kubernetes Apps like a Pro
Codefresh
 
PPTX
Istio + Helm + Canary Webinar
Codefresh
 
PPTX
Selenium Testing your Kubernetes Apps with Machine Learning and Testim
Codefresh
 
PDF
Continuous Delivery for Kubernetes Apps with Helm and ChartMuseum
Codefresh
 
PDF
New Features Webinar-April
Codefresh
 
PDF
Continuous Delivery of Stateful Applications with Kubernetes (in Production)
Codefresh
 
PDF
5 Habits of High-Velocity Teams Using Kubernetes
Codefresh
 
Detect, debug, deploy with Codefresh and Lightstep
Codefresh
 
Simplify Your Code with Helmfile
Codefresh
 
5 Simple Tips for Troubleshooting Your Kubernetes Pods
Codefresh
 
Deploy Secure Cloud-Native Apps Fast
Codefresh
 
Codefresh CICD New Features Launch! May 2019
Codefresh
 
Terraform GitOps on Codefresh
Codefresh
 
Adding Container Image Scanning to Your Codefresh Pipelines with Anchore
Codefresh
 
Image scanning using Clair
Codefresh
 
Updating Kubernetes With Helm Charts: Build, Test, Deploy with Codefresh and...
Codefresh
 
Automated Serverless Pipelines with #GitOps on Codefresh
Codefresh
 
Discovering and Fixing Dependency Vulnerabilities for Kubernetes apps with Sn...
Codefresh
 
Net Pipeline on Windows Kubernetes
Codefresh
 
Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh
Codefresh
 
Skip Staging! Test Docker, Helm, and Kubernetes Apps like a Pro
Codefresh
 
Istio + Helm + Canary Webinar
Codefresh
 
Selenium Testing your Kubernetes Apps with Machine Learning and Testim
Codefresh
 
Continuous Delivery for Kubernetes Apps with Helm and ChartMuseum
Codefresh
 
New Features Webinar-April
Codefresh
 
Continuous Delivery of Stateful Applications with Kubernetes (in Production)
Codefresh
 
5 Habits of High-Velocity Teams Using Kubernetes
Codefresh
 
Ad

Recently uploaded (20)

PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 

Why You Should be Using Multi-stage Docker Builds in 2019

  • 1. Why you should be using Multi-Stage Docker Builds in 2019 GUY SALTON
  • 3. Agenda ● The problem with Docker build ● Solution: Docker multi-stage build ● Docker multi-stage build in CI/CD ● Summary ● Dockerfile and Docker build https://github.com/codefresh-contrib/golang-sample-app/ https://codefresh.io/docs/docs/learn-by-example/golang/golang-hello-world/
  • 4. Docker multi-stage build ● “oh man! thank you! I've been fighting with build times on an image stack for weeks” ● “Wow, this is great for deploying tonnes of microservices!” ● “I've been meaning to use multistage builds, thanks for the walkthrough!” https://www.reddit.com/r/golang/comments/crkibq/docker_golang_reducing_container_size_using/ Multi-stage build is available starting from Docker 17.05 (released in 2017!) - so why now?
  • 5. Dockerfile and 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
  • 7. Demo 1: Docker build on GO app https://github.com/codefresh-contrib/helm-sample-app
  • 8. The Problem with Docker build Image we want Image we build runtime configuration application Compilers, debuggers, ... Linters, tests, profilers, ... code, build and test logs, ... runtime configuration application X (4..10)
  • 9. The Problem with Docker build ● 2 Dockerfiles ○ 1st for build tools ○ 2nd for runtime ● Drawbacks ○ 2+ Dockerfiles ○ Orchestration needed: Bash, make, YAML, ...
  • 10. Solution: Docker multi-stage build ● Benefits ○ One Dockerfile ○ One syntax to learn ○ Same build ■ Local and CI ○ Create multiple stages
  • 13. Docker multi-stage build You can enjoy multi-stage build with every programming language (not only GO): ● GO example - https://codefresh.io/docs/docs/learn-by-example/golang/golang-hello-world/#create-a-multi-stage-docker-image-for-go ● JAVA example - https://codefresh.io/docs/docs/learn-by-example/java/spring-boot-2/#spring-boot-2-and-docker-multi-stage-builds ● Node example - https://codefresh.io/docs/docs/learn-by-example/nodejs/react/#react-and-docker-multi-stage-builds ● PHP example - https://codefresh.io/docs/docs/learn-by-example/php/#the-example-php-project https://codefresh.io/containers/docker-anti-patterns/Docker anti-patterns
  • 14. Codefresh The 1st container-native CI/CD Platform for Microservices Container-native Intuitive & Robust Enterprise Ready Flexible Delivery
  • 15. Demo 3: Docker multi-stage build in CI/CD
  • 16. Summary ● Using 1 Docker image for both build and production results in slow deployment and lots of CVE violations ● Multi-stage build to produce lean, secure and production ready Docker image ● On Codefresh, speedier builds thanks to caching across all images and layers
  • 17. Signup for a FREE account with UNLIMITED builds & schedule a 1:1 with our experts at https://codefresh.io Build Fast, Deploy Faster Thank You! [email protected]