SlideShare a Scribd company logo
TO MAKE BUILDING EASY!
Milindu Kumarage
Software Engineer
Multi-stage Docker builds
A common man app
Let’s talk about a typical web application
Back-end Implementation
• Golang
• Needs Golang to compile
Front-end Implementation
• ReactJS
• Needs Yarn and NodeJS to transpile
A typical web app
A common man app
Serving static files
Static files, the transpiled html,JS,CSS,
images, etc will be served by NGINX
NGINX Server in the front
A common man app
Proxying API Calls
API calls will be proxied to the Go app
A common problem
How we CI/CD this app?
• Install NodeJs, Yarn, Golang, etc on CI/CD?
• Use some docker magic?
A common problem
A common solution
Let’s use some Docker stuff…
One Docker to rule them all?
• Get one Docker, say NodeJS docker.
• Then install Golang and Nginx on it?
Bit from that, bit from this?
• Use NodeJS docker and build the React app, get the build artifacts out
• Use Golang docker and build the API, get the build artifacts out
• Then copy to Nginx docker?
What approach we can use?
A common solution
Docker Version 17.05+
Introducing Docker Multi-stage builds
A common solution
It is like having multiple Dockers
but in one!
• You can define several stages,
using different Docker base
images.
• You can copy files from one stage
to the next stage
A common solution
Docker Multi-stage builds
FROM node:9 AS frontend
WORKDIR /app/web
ADD web .
RUN yarn && yarn build
FROM golang:alpine AS backend
RUN apk add git
WORKDIR /go/src/github.com/agentmilindu/web-api
ADD src .
RUN go get github.com/joho/godotenv github.com/labstack/echo github.com/dgrijalva/jwt-go
RUN go install github.com/agentmilindu/web-api
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=frontend /app/web/build /usr/share/nginx/html
COPY --from=backend /go/bin/web-api /opt/app/api
CMD /opt/app/api
Your final docker image will have only the needed files
No NodeJS, No Yarn, No Golang,
Just NGINX, front-end html, JS, CSS, etc and compiled Go app.
Small Docker images!
A common solution
Let’s get our hands dirty!
Let’s create a multi-stage Docker
github.com/agentmilindu/A-typical-web-app
Thank you

More Related Content

What's hot (20)

PDF
Happy Helming With Okteto
sangam biradar
 
PDF
Automated Serverless Pipelines with #GitOps on Codefresh
Codefresh
 
PDF
Docker for local development
Adam Štipák
 
PPTX
from docker run to docker compose (Webelement #36)
Adam Štipák
 
PDF
Webinar - Continuous Integration with GitLab
OlinData
 
PDF
NLUUG Spring 2012 - OpenShift Primer
Eric D. Schabell
 
PPTX
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
NLJUG
 
PDF
GitLab - Java User Group
PhilippWestphalen
 
PDF
Juc boston2014.pptx
Brandon Mueller
 
PDF
Breaking Bad Habits with GitLab CI
Ivan Nemytchenko
 
PDF
Breaking bad habits with GitLab CI
Ivan Nemytchenko
 
PDF
Jenkins vs GitLab CI
CEE-SEC(R)
 
PDF
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
sangam biradar
 
PDF
Using GitLab CI
ColCh
 
PDF
CI with Gitlab & Docker
Joerg Henning
 
PDF
"Workstation Up" - Docker Development at Flow by Mike Roth
Docker, Inc.
 
PDF
Continuous Integration/Deployment with Gitlab CI
David Hahn
 
PDF
Kubeflow Development Environment
Weiqiang Zhuang
 
PDF
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
Tikal Knowledge
 
PDF
Docker Tooling for Eclipse
Max Andersen
 
Happy Helming With Okteto
sangam biradar
 
Automated Serverless Pipelines with #GitOps on Codefresh
Codefresh
 
Docker for local development
Adam Štipák
 
from docker run to docker compose (Webelement #36)
Adam Štipák
 
Webinar - Continuous Integration with GitLab
OlinData
 
NLUUG Spring 2012 - OpenShift Primer
Eric D. Schabell
 
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
NLJUG
 
GitLab - Java User Group
PhilippWestphalen
 
Juc boston2014.pptx
Brandon Mueller
 
Breaking Bad Habits with GitLab CI
Ivan Nemytchenko
 
Breaking bad habits with GitLab CI
Ivan Nemytchenko
 
Jenkins vs GitLab CI
CEE-SEC(R)
 
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
sangam biradar
 
Using GitLab CI
ColCh
 
CI with Gitlab & Docker
Joerg Henning
 
"Workstation Up" - Docker Development at Flow by Mike Roth
Docker, Inc.
 
Continuous Integration/Deployment with Gitlab CI
David Hahn
 
Kubeflow Development Environment
Weiqiang Zhuang
 
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
Tikal Knowledge
 
Docker Tooling for Eclipse
Max Andersen
 

Similar to Multi-stage Docker builds to make building easy! (20)

PDF
Docker multi-stage build
Alexei Ledenev
 
PDF
Webinar: Using Docker Multi-stage Build to Create Advanced Pipelines
Codefresh
 
PPTX
Pluralsight Webinar: Simplify Your Project Builds with Docker
Elton Stoneman
 
PDF
Butter bei die Fische - Ein Jahr Entwicklung und Produktion mit Docker
johannesunterstein
 
PDF
DockerCon SF 2015: Interconnecting Containers at Scale w/ NGINX
Docker, Inc.
 
PDF
Why You Should be Using Multi-stage Docker Builds in 2019
Codefresh
 
PPTX
Setup docker on existing application
Luc Juggery
 
PPTX
Webapp using docker container
SebyAmin
 
PDF
Containerizing a Web Application with Vue.js and Java
Jadson Santos
 
PPTX
Docker for Development
allingeek
 
PDF
Docker From Scratch
Giacomo Vacca
 
PDF
Deliver Python Apps with Docker
Anton Egorov
 
DOCX
DockerCoreNet
Eimantas Žlabys
 
PPTX
The Future of Web Application Architectures
Lucas Carlson
 
PPTX
Java developer intro to environment management with vagrant puppet and docker
Getting value from IoT, Integration and Data Analytics
 
PDF
Containers, Docker, and Microservices: the Terrific Trio
Jérôme Petazzoni
 
PDF
Scale Big With Docker — Moboom 2014
Jérôme Petazzoni
 
PPTX
Dockerizing react app
Malang QA Community
 
PPTX
Java Developer Intro to Environment Management with Vagrant, Puppet, and Dock...
Lucas Jellema
 
PPTX
Interconnecting containers at scale #Dockercon
sarahnovotny
 
Docker multi-stage build
Alexei Ledenev
 
Webinar: Using Docker Multi-stage Build to Create Advanced Pipelines
Codefresh
 
Pluralsight Webinar: Simplify Your Project Builds with Docker
Elton Stoneman
 
Butter bei die Fische - Ein Jahr Entwicklung und Produktion mit Docker
johannesunterstein
 
DockerCon SF 2015: Interconnecting Containers at Scale w/ NGINX
Docker, Inc.
 
Why You Should be Using Multi-stage Docker Builds in 2019
Codefresh
 
Setup docker on existing application
Luc Juggery
 
Webapp using docker container
SebyAmin
 
Containerizing a Web Application with Vue.js and Java
Jadson Santos
 
Docker for Development
allingeek
 
Docker From Scratch
Giacomo Vacca
 
Deliver Python Apps with Docker
Anton Egorov
 
DockerCoreNet
Eimantas Žlabys
 
The Future of Web Application Architectures
Lucas Carlson
 
Java developer intro to environment management with vagrant puppet and docker
Getting value from IoT, Integration and Data Analytics
 
Containers, Docker, and Microservices: the Terrific Trio
Jérôme Petazzoni
 
Scale Big With Docker — Moboom 2014
Jérôme Petazzoni
 
Dockerizing react app
Malang QA Community
 
Java Developer Intro to Environment Management with Vagrant, Puppet, and Dock...
Lucas Jellema
 
Interconnecting containers at scale #Dockercon
sarahnovotny
 
Ad

Recently uploaded (20)

PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PPTX
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Ad

Multi-stage Docker builds to make building easy!

  • 1. TO MAKE BUILDING EASY! Milindu Kumarage Software Engineer Multi-stage Docker builds
  • 2. A common man app Let’s talk about a typical web application
  • 3. Back-end Implementation • Golang • Needs Golang to compile Front-end Implementation • ReactJS • Needs Yarn and NodeJS to transpile A typical web app A common man app
  • 4. Serving static files Static files, the transpiled html,JS,CSS, images, etc will be served by NGINX NGINX Server in the front A common man app Proxying API Calls API calls will be proxied to the Go app
  • 5. A common problem How we CI/CD this app?
  • 6. • Install NodeJs, Yarn, Golang, etc on CI/CD? • Use some docker magic? A common problem
  • 7. A common solution Let’s use some Docker stuff…
  • 8. One Docker to rule them all? • Get one Docker, say NodeJS docker. • Then install Golang and Nginx on it? Bit from that, bit from this? • Use NodeJS docker and build the React app, get the build artifacts out • Use Golang docker and build the API, get the build artifacts out • Then copy to Nginx docker? What approach we can use? A common solution
  • 9. Docker Version 17.05+ Introducing Docker Multi-stage builds A common solution
  • 10. It is like having multiple Dockers but in one! • You can define several stages, using different Docker base images. • You can copy files from one stage to the next stage A common solution Docker Multi-stage builds
  • 11. FROM node:9 AS frontend WORKDIR /app/web ADD web . RUN yarn && yarn build FROM golang:alpine AS backend RUN apk add git WORKDIR /go/src/github.com/agentmilindu/web-api ADD src . RUN go get github.com/joho/godotenv github.com/labstack/echo github.com/dgrijalva/jwt-go RUN go install github.com/agentmilindu/web-api FROM nginx:alpine COPY nginx.conf /etc/nginx/conf.d/default.conf COPY --from=frontend /app/web/build /usr/share/nginx/html COPY --from=backend /go/bin/web-api /opt/app/api CMD /opt/app/api
  • 12. Your final docker image will have only the needed files No NodeJS, No Yarn, No Golang, Just NGINX, front-end html, JS, CSS, etc and compiled Go app. Small Docker images! A common solution
  • 13. Let’s get our hands dirty! Let’s create a multi-stage Docker github.com/agentmilindu/A-typical-web-app