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

PDF
Testing as a container
ODP
DevAssistant, Docker and You
PDF
Docker based-Pipelines with Codefresh
PDF
Docker Best Practices Workshop
PDF
Gitlab ci-cd
PPTX
Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh
PDF
5 cool ways to get started with Cloud Native Development ( with Okteto)
PPTX
Cloud Native Okteto Cloud
Testing as a container
DevAssistant, Docker and You
Docker based-Pipelines with Codefresh
Docker Best Practices Workshop
Gitlab ci-cd
Multi-cloud CI/CD with failover powered by K8s, Istio, Helm, and Codefresh
5 cool ways to get started with Cloud Native Development ( with Okteto)
Cloud Native Okteto Cloud

What's hot (20)

PDF
Happy Helming With Okteto
PDF
Automated Serverless Pipelines with #GitOps on Codefresh
PDF
Docker for local development
PPTX
from docker run to docker compose (Webelement #36)
PDF
Webinar - Continuous Integration with GitLab
PDF
NLUUG Spring 2012 - OpenShift Primer
PPTX
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
PDF
GitLab - Java User Group
PDF
Juc boston2014.pptx
PDF
Breaking Bad Habits with GitLab CI
PDF
Breaking bad habits with GitLab CI
PDF
Jenkins vs GitLab CI
PDF
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
PDF
Using GitLab CI
PDF
CI with Gitlab & Docker
PDF
"Workstation Up" - Docker Development at Flow by Mike Roth
PDF
Continuous Integration/Deployment with Gitlab CI
PDF
Kubeflow Development Environment
PDF
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
PDF
Docker Tooling for Eclipse
Happy Helming With Okteto
Automated Serverless Pipelines with #GitOps on Codefresh
Docker for local development
from docker run to docker compose (Webelement #36)
Webinar - Continuous Integration with GitLab
NLUUG Spring 2012 - OpenShift Primer
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
GitLab - Java User Group
Juc boston2014.pptx
Breaking Bad Habits with GitLab CI
Breaking bad habits with GitLab CI
Jenkins vs GitLab CI
Dockerize Spago Self Contained ML & NLP Library & Deploy on Okteto Cloud Usin...
Using GitLab CI
CI with Gitlab & Docker
"Workstation Up" - Docker Development at Flow by Mike Roth
Continuous Integration/Deployment with Gitlab CI
Kubeflow Development Environment
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
Docker Tooling for Eclipse
Ad

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

PDF
Docker multi-stage build
PDF
Webinar: Using Docker Multi-stage Build to Create Advanced Pipelines
PPTX
Pluralsight Webinar: Simplify Your Project Builds with Docker
PDF
Butter bei die Fische - Ein Jahr Entwicklung und Produktion mit Docker
PDF
DockerCon SF 2015: Interconnecting Containers at Scale w/ NGINX
PDF
Why You Should be Using Multi-stage Docker Builds in 2019
PPTX
Setup docker on existing application
PPTX
Webapp using docker container
PDF
Containerizing a Web Application with Vue.js and Java
PPTX
Docker for Development
PDF
Docker From Scratch
PDF
Deliver Python Apps with Docker
DOCX
DockerCoreNet
PPTX
The Future of Web Application Architectures
PPTX
Java developer intro to environment management with vagrant puppet and docker
PDF
Containers, Docker, and Microservices: the Terrific Trio
PDF
Scale Big With Docker — Moboom 2014
PPTX
Dockerizing react app
PPTX
Java Developer Intro to Environment Management with Vagrant, Puppet, and Dock...
PPTX
Interconnecting containers at scale #Dockercon
Docker multi-stage build
Webinar: Using Docker Multi-stage Build to Create Advanced Pipelines
Pluralsight Webinar: Simplify Your Project Builds with Docker
Butter bei die Fische - Ein Jahr Entwicklung und Produktion mit Docker
DockerCon SF 2015: Interconnecting Containers at Scale w/ NGINX
Why You Should be Using Multi-stage Docker Builds in 2019
Setup docker on existing application
Webapp using docker container
Containerizing a Web Application with Vue.js and Java
Docker for Development
Docker From Scratch
Deliver Python Apps with Docker
DockerCoreNet
The Future of Web Application Architectures
Java developer intro to environment management with vagrant puppet and docker
Containers, Docker, and Microservices: the Terrific Trio
Scale Big With Docker — Moboom 2014
Dockerizing react app
Java Developer Intro to Environment Management with Vagrant, Puppet, and Dock...
Interconnecting containers at scale #Dockercon
Ad

Recently uploaded (20)

PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Digital Strategies for Manufacturing Companies
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Essential Infomation Tech presentation.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
medical staffing services at VALiNTRY
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
ai tools demonstartion for schools and inter college
PDF
System and Network Administration Chapter 2
PPTX
Transform Your Business with a Software ERP System
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Odoo POS Development Services by CandidRoot Solutions
Wondershare Filmora 15 Crack With Activation Key [2025
Digital Strategies for Manufacturing Companies
How to Choose the Right IT Partner for Your Business in Malaysia
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Essential Infomation Tech presentation.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
medical staffing services at VALiNTRY
Upgrade and Innovation Strategies for SAP ERP Customers
Softaken Excel to vCard Converter Software.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
ai tools demonstartion for schools and inter college
System and Network Administration Chapter 2
Transform Your Business with a Software ERP System
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025

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