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

PDF
CICD Pipelines for Microservices: Lessons from the Trenches
PDF
CICD Pipelines for Microservices Best Practices
PDF
Best Practices for Microservice CI/CD: Lessons from Expedia and Codefresh
PDF
Hybrid CI/CD with Kubernetes & Codefresh
PDF
Making the Most of Helm 3 with Codefresh
PPTX
Docker for dummies
PDF
Docker from a team perspective
PDF
Docker at MoneyBird
CICD Pipelines for Microservices: Lessons from the Trenches
CICD Pipelines for Microservices Best Practices
Best Practices for Microservice CI/CD: Lessons from Expedia and Codefresh
Hybrid CI/CD with Kubernetes & Codefresh
Making the Most of Helm 3 with Codefresh
Docker for dummies
Docker from a team perspective
Docker at MoneyBird

What's hot (20)

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

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

PPTX
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
PDF
Webinar: Using Docker Multi-stage Build to Create Advanced Pipelines
PDF
Docker multi-stage build
PPTX
Multi-stage Docker builds to make building easy!
PPTX
Lean & mean applications using Docker EE and golang
PDF
Docker Multi-Stage Builds
PDF
Scale Big With Docker — Moboom 2014
PDF
‘Hello, world!’ application how to dockerize golang application
PPTX
Simply your Jenkins Projects with Docker Multi-Stage Builds
PDF
VM vs Docker-Based Pipelines
PPTX
Effective images remix
PPTX
Codefresh + Cloud 66 webinar: Testing Strategies for Docker Driven Development
PDF
Building distribution packages with Docker
PDF
Real-World Docker: 10 Things We've Learned
PPTX
Containers #101 Meetup: Building a micro-service using Node.js and Docker - P...
PDF
Perspectives on Docker
PPTX
Getting Started with Docker
PDF
ContainerDays Boston 2015: "Continuous Delivery with Containers" (Nick Gauthier)
PDF
GDGSCL - Docker a jeho provoz v Heroku a AWS
PDF
[@NaukriEngineering] Docker 101
Using Multi-stage Docker, Go, Java,& Bazel to DESTROY Long Build Times
Webinar: Using Docker Multi-stage Build to Create Advanced Pipelines
Docker multi-stage build
Multi-stage Docker builds to make building easy!
Lean & mean applications using Docker EE and golang
Docker Multi-Stage Builds
Scale Big With Docker — Moboom 2014
‘Hello, world!’ application how to dockerize golang application
Simply your Jenkins Projects with Docker Multi-Stage Builds
VM vs Docker-Based Pipelines
Effective images remix
Codefresh + Cloud 66 webinar: Testing Strategies for Docker Driven Development
Building distribution packages with Docker
Real-World Docker: 10 Things We've Learned
Containers #101 Meetup: Building a micro-service using Node.js and Docker - P...
Perspectives on Docker
Getting Started with Docker
ContainerDays Boston 2015: "Continuous Delivery with Containers" (Nick Gauthier)
GDGSCL - Docker a jeho provoz v Heroku a AWS
[@NaukriEngineering] Docker 101
Ad

More from Codefresh (20)

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

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
cuic standard and advanced reporting.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation theory and applications.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
KodekX | Application Modernization Development
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Weekly Chronicles - August'25 Week I
cuic standard and advanced reporting.pdf
The AUB Centre for AI in Media Proposal.docx
Encapsulation theory and applications.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Per capita expenditure prediction using model stacking based on satellite ima...
KodekX | Application Modernization Development
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Dropbox Q2 2025 Financial Results & Investor Presentation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Machine learning based COVID-19 study performance prediction

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! guy.salton@codefresh.io