SlideShare a Scribd company logo
1 of 45
Docker Best
Practices
Some basics to start with
Server
Host OS
Hyper Visor
GuestOS
Bins/
libs
App
A
GuestOS
Bins/
libs
App
A`
GuestOS
Bins/
libs
App
B
Server
Host OS
Docker Engine
Bins/ libs Bins/ libs
AppA
AppA`
AppA`
AppB
AppB`
AppB`
AppB`
AppB`
container
Container vs. VMs
As „ephemeral“ as possible
Single-process-per-container
Docker has layers
Base Image
Dockerfile Docker container with Layers
FROM sonarqube:7.1
Define
Base Image
Layer A
Dockerfile Docker container with Layers
FROM sonarqube:7.1
ENV SONARQUBE_HOME=/opt/sonarqube
Define
Base Image
Layer A
Layer B
Dockerfile Docker container with Layers
FROM sonarqube:7.1
ENV SONARQUBE_HOME=/opt/sonarqube
COPY plugins/branch-2.0.0.jar
$SONARQUBE_HOME/extensions
Define
Base Image
Layer A
Layer B
Layer C
Dockerfile Docker container with Layers
FROM sonarqube:7.1
ENV SONARQUBE_HOME=/opt/sonarqube
COPY plugins/branch-2.0.0.jar
$SONARQUBE_HOME/extensions
RUN dpkg --add-architecture i386 
&& apt-get update 
&& apt-get install -y file git curl zip
Define
Base Image
Layer A
Layer B
Layer C
docker build -t my/container:1.0 .
Build
Docker registry
Push
custom/sonar:v1.1
FROM sonarqube:7.1
ENV SONARQUBE_HOME=/opt/sonarqube
COPY plugins/branch-2.0.0.jar
$SONARQUBE_HOME/extensions
RUN dpkg --add-architecture i386 
&& apt-get update 
&& apt-get install -y file git curl zip
docker push my/container :1.0
copy to temp
Base Image
Layer A
Layer B
Layer C
Build
Docker build context
docker build -t my/container:1.0 .
Build Context Pfad
/var/lib/docker/tmp/docker-builder001817348/
Base Image
Layer A
Layer B
Layer C
docker build -t my/container:1.0 .
Build
FROM sonarqube:7.1
ENV SONARQUBE_HOME=/opt/sonarqube
COPY plugins/branch-2.0.0.jar
$SONARQUBE_HOME/extensions
RUN dpkg --add-architecture i386 
&& apt-get update 
&& apt-get install -y file git curl zip
Build Cache
cached
Build
cached
Build
Docker build cache
Best Practices
Optimize Build Time
https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/
https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/
https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/
copy to temp
Base Image
Layer A
Layer B
Layer C
Build
Use .dockerignore to reduce context
docker build -t my/container:1.0 . /var/lib/docker/tmp/docker-builder001817348/
Reduce image size
https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/
https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/
https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/
Maintainability
https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/
https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/
User minimal images
https://snyk.io/blog/10-docker-image-security-best-practices/
Use Least privileged user
Having an application on the container run with the root user further broadens
the attack surface and enables an easy path to privilege escalation if the application
itself is vulnerable to exploitation.
UID & GUID
Use the same UID and GUID for interacting container
Container A
user: worker (uuid 500)
group: worker (guid 500)
Container B
user: worker (uuid 600)
group: worker (guid 600)
Write Files read Files
X
Don’t leak sensitive information to Docker images
https://snyk.io/blog/10-docker-image-security-best-practices/
Using multi-stage builds when using secrets
By leveraging Docker support for multi-stage builds, fetch and manage
secrets in an intermediate image layer that is later disposed of so that no
sensitive data reaches the image build
https://snyk.io/blog/10-docker-image-security-best-practices/
Using Docker secret commands
Use an alpha feature in Docker for managing secrets to mount sensitive
files without caching them.
COPY . .
Beware of recursive copy
COPY VS. ADD
Use COPY instead of ADD
What is your best pratice?
Further Topics
Security-
Enhanced
Linux
(SELinux) … ?
https://en.wikipedia.org/wiki/Security-Enhanced_Linux#/media/File:SELinux_logo.svg
+
https://people.redhat.com/duffy/selinux/selinux-coloring-book_A4-Stapled.pdf
=
Docker
image
Scanner
Base Image
Layer A
Layer B
Layer C
https://res.cloudinary.com/snyk/image/upload/v1551121069/Number_of_OS_vulnerabilities_by_docker_image.png
Next Steps @ home
https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/
https://snyk.io/blog/10-docker-image-security-best-practices/
https://res.cloudinary.com/snyk/image/upload/v1551798390/Docker_Image_Security_Best_Practices_.pdf
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
Monitoring@AWS / Architectural Draft / 2017-06-13 b 45
Thank you!

More Related Content

What's hot

What's hot (20)

Infrastructure as a code: a cloud approach
Infrastructure as a code: a cloud approachInfrastructure as a code: a cloud approach
Infrastructure as a code: a cloud approach
 
Amazon Elastic Container Service for Kubernetes (Amazon EKS) I AWS Dev Day 2018
Amazon Elastic Container Service for Kubernetes (Amazon EKS) I AWS Dev Day 2018Amazon Elastic Container Service for Kubernetes (Amazon EKS) I AWS Dev Day 2018
Amazon Elastic Container Service for Kubernetes (Amazon EKS) I AWS Dev Day 2018
 
IDI 2020 - Containers Meet Serverless
IDI 2020 - Containers Meet ServerlessIDI 2020 - Containers Meet Serverless
IDI 2020 - Containers Meet Serverless
 
Introduction to EKS (AWS User Group Slovakia)
Introduction to EKS (AWS User Group Slovakia)Introduction to EKS (AWS User Group Slovakia)
Introduction to EKS (AWS User Group Slovakia)
 
Introducing AWS Fargate
Introducing AWS FargateIntroducing AWS Fargate
Introducing AWS Fargate
 
CI&CD on AWS - Meetup Roma Oct 2016
CI&CD on AWS - Meetup Roma Oct 2016CI&CD on AWS - Meetup Roma Oct 2016
CI&CD on AWS - Meetup Roma Oct 2016
 
Using Containers on AWS
Using Containers on AWSUsing Containers on AWS
Using Containers on AWS
 
AWS Container services
AWS Container servicesAWS Container services
AWS Container services
 
Advanced workload scheduling for containers on AWS
Advanced workload scheduling for containers on AWSAdvanced workload scheduling for containers on AWS
Advanced workload scheduling for containers on AWS
 
IaC on AWS Cloud
IaC on AWS CloudIaC on AWS Cloud
IaC on AWS Cloud
 
Introduction to EKS and eksctl
Introduction to EKS and eksctlIntroduction to EKS and eksctl
Introduction to EKS and eksctl
 
Docker clusters on AWS with Amazon ECS and Kubernetes
Docker clusters on AWS with Amazon ECS and KubernetesDocker clusters on AWS with Amazon ECS and Kubernetes
Docker clusters on AWS with Amazon ECS and Kubernetes
 
Ultimate kubernetes platform on aws with eks
Ultimate kubernetes platform on aws with eksUltimate kubernetes platform on aws with eks
Ultimate kubernetes platform on aws with eks
 
A Pathway to Continuous Integration/Continuous Delivery on AWS
A Pathway to Continuous Integration/Continuous Delivery on AWSA Pathway to Continuous Integration/Continuous Delivery on AWS
A Pathway to Continuous Integration/Continuous Delivery on AWS
 
AWS ECS vs EKS
AWS ECS vs EKSAWS ECS vs EKS
AWS ECS vs EKS
 
Kubernetes on AWS gone wild
Kubernetes on AWS gone wildKubernetes on AWS gone wild
Kubernetes on AWS gone wild
 
Infrastructure as Code on AWS
Infrastructure as Code on AWSInfrastructure as Code on AWS
Infrastructure as Code on AWS
 
AWS re:Invent 2016: Workshop: Deploy a Deep Learning Framework on Amazon ECS ...
AWS re:Invent 2016: Workshop: Deploy a Deep Learning Framework on Amazon ECS ...AWS re:Invent 2016: Workshop: Deploy a Deep Learning Framework on Amazon ECS ...
AWS re:Invent 2016: Workshop: Deploy a Deep Learning Framework on Amazon ECS ...
 
Serverless architectures on aws
Serverless architectures on awsServerless architectures on aws
Serverless architectures on aws
 
Intro to AWS Developer Tools, featuring AWS CodeStar
Intro to AWS Developer Tools, featuring AWS CodeStarIntro to AWS Developer Tools, featuring AWS CodeStar
Intro to AWS Developer Tools, featuring AWS CodeStar
 

Similar to Docker best practices

Be a Happier Developer with Docker: Tricks of the Trade
Be a Happier Developer with Docker: Tricks of the TradeBe a Happier Developer with Docker: Tricks of the Trade
Be a Happier Developer with Docker: Tricks of the Trade
Docker, Inc.
 

Similar to Docker best practices (20)

BBL Premiers pas avec Docker
BBL Premiers pas avec DockerBBL Premiers pas avec Docker
BBL Premiers pas avec Docker
 
Docker in production
Docker in productionDocker in production
Docker in production
 
Develop with docker 2014 aug
Develop with docker 2014 augDevelop with docker 2014 aug
Develop with docker 2014 aug
 
Docker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini AnandDocker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini Anand
 
Be a happier developer with Docker: Tricks of the trade
Be a happier developer with Docker: Tricks of the tradeBe a happier developer with Docker: Tricks of the trade
Be a happier developer with Docker: Tricks of the trade
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안
 
Docker: A New Way to Turbocharging Your Apps Development
Docker: A New Way to Turbocharging Your Apps DevelopmentDocker: A New Way to Turbocharging Your Apps Development
Docker: A New Way to Turbocharging Your Apps Development
 
Cloud read java with kubernetes
Cloud read java with kubernetesCloud read java with kubernetes
Cloud read java with kubernetes
 
Unleashing Docker with Pipelines in Bitbucket Cloud
Unleashing Docker with Pipelines in Bitbucket CloudUnleashing Docker with Pipelines in Bitbucket Cloud
Unleashing Docker with Pipelines in Bitbucket Cloud
 
Be a Happier Developer with Docker: Tricks of the Trade
Be a Happier Developer with Docker: Tricks of the TradeBe a Happier Developer with Docker: Tricks of the Trade
Be a Happier Developer with Docker: Tricks of the Trade
 
時代在變 Docker 要會:台北 Docker 一日入門篇
時代在變 Docker 要會:台北 Docker 一日入門篇時代在變 Docker 要會:台北 Docker 一日入門篇
時代在變 Docker 要會:台北 Docker 一日入門篇
 
Dockerize your Symfony application - Symfony Live NYC 2014
Dockerize your Symfony application - Symfony Live NYC 2014Dockerize your Symfony application - Symfony Live NYC 2014
Dockerize your Symfony application - Symfony Live NYC 2014
 
How to Dockerize Web Application using Docker Compose
How to Dockerize Web Application using Docker ComposeHow to Dockerize Web Application using Docker Compose
How to Dockerize Web Application using Docker Compose
 
How to _docker
How to _dockerHow to _docker
How to _docker
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Docker for developers z java
Docker for developers z javaDocker for developers z java
Docker for developers z java
 
Faster and Easier Software Development using Docker Platform
Faster and Easier Software Development using Docker PlatformFaster and Easier Software Development using Docker Platform
Faster and Easier Software Development using Docker Platform
 
Dockerfiles building docker images automatically v (workdir, env, add, and ...
Dockerfiles   building docker images automatically v (workdir, env, add, and ...Dockerfiles   building docker images automatically v (workdir, env, add, and ...
Dockerfiles building docker images automatically v (workdir, env, add, and ...
 
Docker for Dummies
Docker for DummiesDocker for Dummies
Docker for Dummies
 

Recently uploaded

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 

Recently uploaded (20)

MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 

Docker best practices