SlideShare a Scribd company logo
Simplify your Jenkins Projects with
Docker Multi-Stage Builds
Eric Smalling - Solution Architect, Docker Inc.
Simplify your Jenkins Projects
with Docker Multi-Stage Builds
Eric Smalling
Solution Architect
Docker Inc.
Agenda
‱ Docker images 101
‱Building images via Jenkins
‱ Image size challenges
‱ Old way: Using Docker image builder pattern
‱ New way: Docker multi-stage builds
‱ Demos
‱ Resources for more info
Introduction
‱ Eric Smalling
–Solution Architect
Docker Customer Success Team
‱ ~25 years in software development, architecture,
version control admin, etc

–Java / J2EE, C, Python, etc
–Puppet, Ansible
–Git, SVN, CVS, ClearCase, VSS, PVCS
‱ ~10 years in build & test automation
–Primarily Jenkins for CI, including some very large scale
implementations
–Testing with Selenium, Fitnesse, RESTAssured, SOAPUI,
Puppet-RSpec, etc
–Docker user since pre-1.0 days
‱Dallas/Fort Worth Jenkins Area Meetup (JAM)
coordinator.
Docker images 101
‱ Images are built up from a series of
layers
‱ Each layer represents changes from
the prior
‱ Layers are immutable (read-only)
and referenced by hashes and
optional tags
‱Containers run with a file system
based on an image with a thin
read/write layer added.
(plus any volume mounts specified)
Image credit: https://docs.docker.com/engine/userguide/storagedriver/imagesandcontainers
Docker images 101
‱ Multiple containers
running on the same
image share the
underlying layers.
‱ Each container
overlays it’s own
container read/write
layer.
Image credit: https://docs.docker.com/engine/userguide/storagedriver/imagesandcontainers
Building images via Jenkins
‱ 3 usual methods:
– Shell step
– Docker build
step (plugin)
– Pipeline DSL
Building images via Jenkins
...
Image size challenges
‱ Image layers have size and they add up!
‱ CI can compound this
‱ Example: dockercraft
–Base golang:1.7.1 = 672MB
–Docker 17.06 CE = 98MB
–Cuberite = 12MB
–Misc = 56 MB
–Total: 838MB!
Image size challenges
‱ Image layers have size and they add up!
‱ CI can compound this
‱ Example: dockercraft
–Base golang:1.7.1 = 672MB debian:jessie = 123MB
–Docker 17.06 CE = 98MB
–Cuberite = 12MB
–Misc = 56 MB
–Total: 838MB! 289MB
Changing the base all by itself
saves us 549MB!
Image size challenges
How can we get rid of GoLang if it’s needed?
Build in Jenkins-land, then Dockerize
‱ Use Jenkins build steps to do the construction in the
workspace followed by a Docker image build with just the
needed artifacts
node {
def app
stage('SCM clone') {
checkout scm
}
stage ('Build Image') {
app = docker.build("m
}
stage ('Print image info')
{
sh 'docker image ls my
sh 'docker image histo
}
}
Jenkinsfile
FROM debian:jessie
COPY build_artifacts /
# Copy Dockercraft config and p
COPY ./config /srv/Server
COPY ./docs/img/logo64x64.png /
COPY ./Docker /srv/Server/Plugi
Dockerfile
Build
artifacts
Small
deployment
image
Docker build pattern
‱ Using Docker image builder pattern, we break the
Dockerfile up into multiple files, the final one being the
one that produces the image to ship.
FROM golang:1.7.1
ENV DOCKER_VERSION 1.12.1
ENV CUBERITE_BUILD 630
# Copy latest docker client(s)
RUN curl -sSL -o docker.tgz ht
tar -xvf
docker.tgz
chmod +x
/bin/docker
ln -s
/bin/docker /b
# Download Cuberite server (Mi
WORKDIR /srv
RUN curl "https://builds.cuber
# Copy Dockercraft config and
COPY ./config /srv/Server
COPY ./docs/img/logo64x64.png
COPY ./Docker /srv/Server/Plug
# Copy Go code and install
Dockerfile FROM golang:1.7.1
ENV DOCKER_VERSION 1.12.1
ENV CUBERITE_BUILD 630
# Copy latest docker client(s)
RUN curl -sSL -o docker.tgz ht
tar -xvf
docker.tgz
chmod +x
/bin/docker
ln -s
/bin/docker /b
Dockerfile
FROM debian:jessie
COPY build_artifacts /
# Copy Dockercraft config and p
COPY ./config /srv/Server
COPY ./docs/img/logo64x64.png /
COPY ./Docker /srv/Server/Plugi
Dockerfile
Big build
image
Smaller
deployment
image
node {
def app
stage('SCM clone') {
checkout scm
}
stage ('Build Image') {
app = docker.build("m
}
stage ('Print image info')
{
sh 'docker image ls my
sh 'docker image histo
}
}
Jenkinsfile
Old School Way
‱ Implementing some fashion of the builder pattern via build
steps or multiple projects triggering each other.
FROM golang:1.7.1
ENV DOCKER_VERSION 1.12.1
ENV CUBERITE_BUILD 630
# Copy latest docker client(s)
RUN curl -sSL -o docker.tgz ht
tar -xvf
docker.tgz
chmod +x
/bin/docker
ln -s
/bin/docker /b
Dockerfile
FROM debian:jessie
COPY build_artifacts /
# Copy Dockercraft config and p
COPY ./config /srv/Server
COPY ./docs/img/logo64x64.png /
COPY ./Docker /srv/Server/Plugi
Dockerfile
Big build
image
Smaller
deployment
image
https://cdn.meme.am/instances/500x/76014521/you-cant-break-a-build-if-its-too-complicated-to-change.jpg
Docker image builds demo (old way)
Demo time!
Docker Multi-Stage builds
‱ Multiple stages in one Dockerfile
‱ Each stage starts with a new “FROM” line
‱ Layers from final stage are the only ones in your image
‱ Stages can refer back to and copy files from earlier stages
‱ Requires Docker CE 17.05+ / EE 17.06+
Example Dockerfile with multi-stage:
Example Dockerfile with multi-stage:
wget
docker cuberite
}alpine
golang debian
myappdockercraft
Minecraft, really?
Not everyone works at Unicorn shops that code in GoLang all
day and visualize their Docker containers in Minecraft
http://gph.is/1UK1ZFa
Simple web app:
‱ ReactJS front-end
‱ Spring Boot, Java back-end
‱ Deployed in single container
AtSeaApp Demo
AtSeaApp Demo
Demo time!
Resources
‱ Dockercon 2017 keynote introducing Multi-Stage Builds:
https://youtu.be/hwkqju_BXEo?t=24m26s
‱ Abby Fuller, Creating Effective Images:
https://youtu.be/pPsREQbf3PA
‱Nicolas Frankel, A Dockerfile for Maven-Based GitHub
Projects: https://goo.gl/hWv3NM
Resources
COPENHAGEN, DENMARK
Q & A
Contact me
Eric Smalling
Solution Architect at Docker
eric.smalling@docker.com
ericsmalling
}
COPENHAGEN, DENMARK
Simply your Jenkins Projects with Docker Multi-Stage Builds

More Related Content

PPTX
Code metrics
PDF
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
PDF
Power-up services with gRPC
PPTX
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
PPTX
CI, CD, CT, Deploy, IaaS, DevOps, Stage
PDF
Gitlab ci, cncf.sk
PPT
OpenDaylight Integration with OpenStack Neutron: A Tutorial
PDF
Micro XRCE-DDS and micro-ROS
Code metrics
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
Power-up services with gRPC
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
CI, CD, CT, Deploy, IaaS, DevOps, Stage
Gitlab ci, cncf.sk
OpenDaylight Integration with OpenStack Neutron: A Tutorial
Micro XRCE-DDS and micro-ROS

What's hot (20)

PDF
ISACA DevOps LATAM
PDF
Docker Registry V2
PDF
Head first docker
ODP
OpenShift Enterprise
PDF
Using GitLab CI
 
PPTX
Multi Stage Docker Build
PDF
Docker multi-stage build
PPTX
DoD Enterprise DevSecOps Initiative by Mr. Nicolas Chaillan
PDF
Rust Embedded Development on ESP32 and basics of Async with Embassy
PDF
Gitlab CI : Integration et Déploiement Continue
PDF
Introduction to Docker - IndiaOpsUG
PDF
DALIă«ă‚ˆă‚‹ç…§æ˜Žćˆ¶ćŸĄăšKNXに぀いお
PPTX
Containerization and Docker
PPT
Epidemiology of Poliomyelitis
PDF
Docker Introduction
PPTX
Japanese encephalitis
DOCX
Importance of immunization
PPTX
Holographic versatile disk
PPTX
PPTX
Introduction to Gitlab | Gitlab 101 | Training Session
ISACA DevOps LATAM
Docker Registry V2
Head first docker
OpenShift Enterprise
Using GitLab CI
 
Multi Stage Docker Build
Docker multi-stage build
DoD Enterprise DevSecOps Initiative by Mr. Nicolas Chaillan
Rust Embedded Development on ESP32 and basics of Async with Embassy
Gitlab CI : Integration et Déploiement Continue
Introduction to Docker - IndiaOpsUG
DALIă«ă‚ˆă‚‹ç…§æ˜Žćˆ¶ćŸĄăšKNXに぀いお
Containerization and Docker
Epidemiology of Poliomyelitis
Docker Introduction
Japanese encephalitis
Importance of immunization
Holographic versatile disk
Introduction to Gitlab | Gitlab 101 | Training Session
Ad

Similar to Simply your Jenkins Projects with Docker Multi-Stage Builds (20)

PPTX
Reduce DevOps Friction with Docker & Jenkins by Andy Pemberton, Cloudbees
PDF
Rapid Development With Docker Compose
PPTX
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
 
PDF
Serverless Container with Source2Image
PDF
Serverless containers 
 with source-to-image
PDF
DCEU 18: Building Your Development Pipeline
PPTX
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
PDF
Dockercon EU 2014
PDF
Docker 101 Workshop slides (JavaOne 2017)
PDF
The Fairy Tale of the One Command Build Script
PDF
DevOps Workflow: A Tutorial on Linux Containers
PDF
Up and running with docker
PPTX
ABCing docker with environments - workshop
PDF
Docker Containers: Developer’s experience and building robust developer envir...
PDF
Docker and Puppet for Continuous Integration
PDF
Docker From Scratch
PDF
[@NaukriEngineering] Docker 101
PDF
IntroducciĂłn a contenedores Docker
PPTX
How to _docker
PPTX
Reduce DevOps Friction with Docker & Jenkins by Andy Pemberton, Cloudbees
Rapid Development With Docker Compose
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
 
Serverless Container with Source2Image
Serverless containers 
 with source-to-image
DCEU 18: Building Your Development Pipeline
The Tale of a Docker-based Continuous Delivery Pipeline by Rafe Colton (ModCl...
Dockercon EU 2014
Docker 101 Workshop slides (JavaOne 2017)
The Fairy Tale of the One Command Build Script
DevOps Workflow: A Tutorial on Linux Containers
Up and running with docker
ABCing docker with environments - workshop
Docker Containers: Developer’s experience and building robust developer envir...
Docker and Puppet for Continuous Integration
Docker From Scratch
[@NaukriEngineering] Docker 101
IntroducciĂłn a contenedores Docker
How to _docker
Ad

More from Eric Smalling (19)

PDF
DockerCon 2023 - Live Demo_Hardening Against Kubernetes Hacks.pdf
PDF
KubeHuddle NA 2023 - Why should devs care about container security - Eric Sma...
PDF
ATO 2022 - Why should devs care about container security.pdf
PDF
KubeCon NA 2022 - Hardening against Kubernetes Hacks.pdf
PDF
DevOpsDays Chicago 2022 - Hands-on hacking containers and ways to prevent it
PDF
Look Ma' - Building Java and Go based container images without Dockerfiles
PDF
Container Stranger Danger - Why should devs care about container security
PDF
SCaLE 19x - Eric Smalling - Hardening against Kubernetes Hacks
PDF
DockerCon 2022 - From legacy to Kubernetes, securely & quickly
PDF
Python Web Conference 2022 - Why should devs care about container security.pdf
PDF
Why should developers care about container security?
PDF
AWS live hack: Docker + Snyk Container on AWS
PDF
AWS live hack: Atlassian + Snyk OSS on AWS
PDF
Hacking into your containers, and how to stop it!
PDF
DevSecCon Lightning 2021- Container defaults are a hackers best friend
PDF
LFX Nov 16, 2021 - Find vulnerabilities before security knocks on your door
PDF
So. many. vulnerabilities. Why are containers such a mess and what to do abou...
PDF
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
PDF
Best Practices for Developing & Deploying Java Applications with Docker
DockerCon 2023 - Live Demo_Hardening Against Kubernetes Hacks.pdf
KubeHuddle NA 2023 - Why should devs care about container security - Eric Sma...
ATO 2022 - Why should devs care about container security.pdf
KubeCon NA 2022 - Hardening against Kubernetes Hacks.pdf
DevOpsDays Chicago 2022 - Hands-on hacking containers and ways to prevent it
Look Ma' - Building Java and Go based container images without Dockerfiles
Container Stranger Danger - Why should devs care about container security
SCaLE 19x - Eric Smalling - Hardening against Kubernetes Hacks
DockerCon 2022 - From legacy to Kubernetes, securely & quickly
Python Web Conference 2022 - Why should devs care about container security.pdf
Why should developers care about container security?
AWS live hack: Docker + Snyk Container on AWS
AWS live hack: Atlassian + Snyk OSS on AWS
Hacking into your containers, and how to stop it!
DevSecCon Lightning 2021- Container defaults are a hackers best friend
LFX Nov 16, 2021 - Find vulnerabilities before security knocks on your door
So. many. vulnerabilities. Why are containers such a mess and what to do abou...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
Best Practices for Developing & Deploying Java Applications with Docker

Recently uploaded (20)

PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Introduction to Artificial Intelligence
PPT
Introduction Database Management System for Course Database
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
AI in Product Development-omnex systems
PDF
medical staffing services at VALiNTRY
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
top salesforce developer skills in 2025.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
ai tools demonstartion for schools and inter college
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Transform Your Business with a Software ERP System
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Upgrade and Innovation Strategies for SAP ERP Customers
Wondershare Filmora 15 Crack With Activation Key [2025
Introduction to Artificial Intelligence
Introduction Database Management System for Course Database
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
2025 Textile ERP Trends: SAP, Odoo & Oracle
Adobe Illustrator 28.6 Crack My Vision of Vector Design
AI in Product Development-omnex systems
medical staffing services at VALiNTRY
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
top salesforce developer skills in 2025.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
ai tools demonstartion for schools and inter college
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Transform Your Business with a Software ERP System
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Design an Analysis of Algorithms II-SECS-1021-03
Navsoft: AI-Powered Business Solutions & Custom Software Development

Simply your Jenkins Projects with Docker Multi-Stage Builds

  • 1. Simplify your Jenkins Projects with Docker Multi-Stage Builds Eric Smalling - Solution Architect, Docker Inc.
  • 2. Simplify your Jenkins Projects with Docker Multi-Stage Builds Eric Smalling Solution Architect Docker Inc.
  • 3. Agenda ‱ Docker images 101 ‱Building images via Jenkins ‱ Image size challenges ‱ Old way: Using Docker image builder pattern ‱ New way: Docker multi-stage builds ‱ Demos ‱ Resources for more info
  • 4. Introduction ‱ Eric Smalling –Solution Architect Docker Customer Success Team ‱ ~25 years in software development, architecture, version control admin, etc
 –Java / J2EE, C, Python, etc –Puppet, Ansible –Git, SVN, CVS, ClearCase, VSS, PVCS ‱ ~10 years in build & test automation –Primarily Jenkins for CI, including some very large scale implementations –Testing with Selenium, Fitnesse, RESTAssured, SOAPUI, Puppet-RSpec, etc –Docker user since pre-1.0 days ‱Dallas/Fort Worth Jenkins Area Meetup (JAM) coordinator.
  • 5. Docker images 101 ‱ Images are built up from a series of layers ‱ Each layer represents changes from the prior ‱ Layers are immutable (read-only) and referenced by hashes and optional tags ‱Containers run with a file system based on an image with a thin read/write layer added. (plus any volume mounts specified) Image credit: https://docs.docker.com/engine/userguide/storagedriver/imagesandcontainers
  • 6. Docker images 101 ‱ Multiple containers running on the same image share the underlying layers. ‱ Each container overlays it’s own container read/write layer. Image credit: https://docs.docker.com/engine/userguide/storagedriver/imagesandcontainers
  • 7. Building images via Jenkins ‱ 3 usual methods: – Shell step – Docker build step (plugin) – Pipeline DSL
  • 8. Building images via Jenkins ...
  • 9. Image size challenges ‱ Image layers have size and they add up! ‱ CI can compound this ‱ Example: dockercraft –Base golang:1.7.1 = 672MB –Docker 17.06 CE = 98MB –Cuberite = 12MB –Misc = 56 MB –Total: 838MB!
  • 10. Image size challenges ‱ Image layers have size and they add up! ‱ CI can compound this ‱ Example: dockercraft –Base golang:1.7.1 = 672MB debian:jessie = 123MB –Docker 17.06 CE = 98MB –Cuberite = 12MB –Misc = 56 MB –Total: 838MB! 289MB Changing the base all by itself saves us 549MB!
  • 11. Image size challenges How can we get rid of GoLang if it’s needed?
  • 12. Build in Jenkins-land, then Dockerize ‱ Use Jenkins build steps to do the construction in the workspace followed by a Docker image build with just the needed artifacts node { def app stage('SCM clone') { checkout scm } stage ('Build Image') { app = docker.build("m } stage ('Print image info') { sh 'docker image ls my sh 'docker image histo } } Jenkinsfile FROM debian:jessie COPY build_artifacts / # Copy Dockercraft config and p COPY ./config /srv/Server COPY ./docs/img/logo64x64.png / COPY ./Docker /srv/Server/Plugi Dockerfile Build artifacts Small deployment image
  • 13. Docker build pattern ‱ Using Docker image builder pattern, we break the Dockerfile up into multiple files, the final one being the one that produces the image to ship. FROM golang:1.7.1 ENV DOCKER_VERSION 1.12.1 ENV CUBERITE_BUILD 630 # Copy latest docker client(s) RUN curl -sSL -o docker.tgz ht tar -xvf docker.tgz chmod +x /bin/docker ln -s /bin/docker /b # Download Cuberite server (Mi WORKDIR /srv RUN curl "https://builds.cuber # Copy Dockercraft config and COPY ./config /srv/Server COPY ./docs/img/logo64x64.png COPY ./Docker /srv/Server/Plug # Copy Go code and install Dockerfile FROM golang:1.7.1 ENV DOCKER_VERSION 1.12.1 ENV CUBERITE_BUILD 630 # Copy latest docker client(s) RUN curl -sSL -o docker.tgz ht tar -xvf docker.tgz chmod +x /bin/docker ln -s /bin/docker /b Dockerfile FROM debian:jessie COPY build_artifacts / # Copy Dockercraft config and p COPY ./config /srv/Server COPY ./docs/img/logo64x64.png / COPY ./Docker /srv/Server/Plugi Dockerfile Big build image Smaller deployment image node { def app stage('SCM clone') { checkout scm } stage ('Build Image') { app = docker.build("m } stage ('Print image info') { sh 'docker image ls my sh 'docker image histo } } Jenkinsfile
  • 14. Old School Way ‱ Implementing some fashion of the builder pattern via build steps or multiple projects triggering each other. FROM golang:1.7.1 ENV DOCKER_VERSION 1.12.1 ENV CUBERITE_BUILD 630 # Copy latest docker client(s) RUN curl -sSL -o docker.tgz ht tar -xvf docker.tgz chmod +x /bin/docker ln -s /bin/docker /b Dockerfile FROM debian:jessie COPY build_artifacts / # Copy Dockercraft config and p COPY ./config /srv/Server COPY ./docs/img/logo64x64.png / COPY ./Docker /srv/Server/Plugi Dockerfile Big build image Smaller deployment image https://cdn.meme.am/instances/500x/76014521/you-cant-break-a-build-if-its-too-complicated-to-change.jpg
  • 15. Docker image builds demo (old way) Demo time!
  • 16. Docker Multi-Stage builds ‱ Multiple stages in one Dockerfile ‱ Each stage starts with a new “FROM” line ‱ Layers from final stage are the only ones in your image ‱ Stages can refer back to and copy files from earlier stages ‱ Requires Docker CE 17.05+ / EE 17.06+
  • 17. Example Dockerfile with multi-stage:
  • 18. Example Dockerfile with multi-stage: wget docker cuberite }alpine golang debian myappdockercraft
  • 19. Minecraft, really? Not everyone works at Unicorn shops that code in GoLang all day and visualize their Docker containers in Minecraft http://gph.is/1UK1ZFa
  • 20. Simple web app: ‱ ReactJS front-end ‱ Spring Boot, Java back-end ‱ Deployed in single container AtSeaApp Demo
  • 22. Resources ‱ Dockercon 2017 keynote introducing Multi-Stage Builds: https://youtu.be/hwkqju_BXEo?t=24m26s ‱ Abby Fuller, Creating Effective Images: https://youtu.be/pPsREQbf3PA ‱Nicolas Frankel, A Dockerfile for Maven-Based GitHub Projects: https://goo.gl/hWv3NM
  • 24. Q & A
  • 25. Contact me Eric Smalling Solution Architect at Docker eric.smalling@docker.com ericsmalling } COPENHAGEN, DENMARK