SlideShare a Scribd company logo
Dockerfiles & Best Practices
#BDay4
Avash Mulmi
● Mozilla Representative for Nepal
● Volunteer, FOSS Nepal Community
● Docker Meetup Organizer
Agenda
● What are Dockerfiles?
● Usage
● Best Practices
Dockerfile(s)?
● Textfile, named Dockerfile
● Contains commands, in sequential order
● Used to build an image
● Have own format and instruction set
Dockerfile
Dockerfile(s)?
Building Images
● Change WORKDIR to Folder with Dockerfile (General Practice)
● ~# docker build .
● ~# docker build -t IMAGE_NAME:Tag .
● ~# docker build -t IMAGE_NAME:Tag -f Dockerfile /path/to/Dockerfile
Working with Built Image
● Check for built image:
 ~# docker images
● Saving built image:
 ~# docker save IMAGENAME > image.tar
● Deleting/Removing built image:
 ~# docker rmi IMAGENAME
 ~# docker rmi IMAGE_ID
Best Practices
● Ephemeral Containers
● Using .dockerignore file
● As lightweight as possible
● Minimize the number of layers
● One container, One purpose
● Use volumes
● Avoid using root user
Ephemeral Containers
● Containers should be ephemeral
● Literal meaning of Ephemeral → Short lived, brief, momentary
● Stopped, Destroyed and New one built with minimum set-up &
configurations
● Good and Complete Dockerfile can achieve this easily
.dockerignore
● Similar to .gitignore
● Generally Dockerfile is in an empty directory
● In some cases, we need to add files and directories to the
containers
● In such cases, use .dockerignore in those directories to skip files
that are not required at all
Lightweight
● Install only required packages
● It can reduce complexity, dependencies, file size and build times
● Some applications ‘might’ look important for future
● For eg: a text editor in a database image
● Make image as small as possible using light base images where
possible
Minimize Number of Layers
● Each RUN command creates a new layer
● Need to know figure out how to minimize the number of layers
● Example 1: update, upgrade and installation of packages can stay
in a single RUN command with multi-line arguments
● Example 2: download of a zip file, extraction and move to another
folder
● Benefits: docker pull and docker push are faster, reduces
complexity of an image etc.
Example 1
● RUN apt-get update
RUN apt-get install apache2 git mysql-server php5 vim
RUN apt-get clean
● RUN apt-get update 
&& apt-get install apache2 git mysql-server php5 vim 
&& apt-get clean
Example 2
● RUN curl http://192.168.100.5/file.tar.gz
RUN tar xvf file.tar.gz
RUN mv EXTRACTED_FILE /opt/
● RUN curl http://192.168.100.5/file.tar.gz | tar xvf -C /opt/
Example 3
● RUN apt-get update 
&& apt-get install apache2 git mysql-server php5 vim 
&& apt-get clean
RUN curl http://192.168.100.5/file.tar.gz | tar xvf -C /opt/
RUN cp /etc/someconfig /opt/someconfig 
&& ln -s /usr/share/app1/default.cfg /opt/default.cfg
● RUN apt-get update 
&& apt-get install apache2 git mysql-server php5 vim 
&& apt-get clean 
&& curl | tar xvf -C /opt/ 
&& cp /etc/someconfig /opt/someconfig 
&& ln -s /usr/share/app1/default.cfg /opt/default.cfg 
&& cd /opt/ && ./configure && make && make install 
&& rm old_unnecessary_files
One Container, One Purpose
● Keep containers as clean and modular as possible
● Creating containers for different dependent applications and
linking them makes it easier to maintain & reuse those containers
● Eg: Instead of single container with webserver, database and
(php), three separate containers with webserver, database and
(php) in each is better.
● Why? → Maintenance & Reusablity
Use Volumes
● Do not store data in containers, as far as possible
● Use Volumes to store data
● Concept of ephemeral
● App container running v1.9 should be easily stopped, destroyed
and updated with container running v2.0 without losing any data
Avoid using `root` user
● By default docker runs containers with root user
● If possible use a normal user
● Depends on situation
Delete unnecessary files
● Reduces size of image and container
● Eg:
RUN curl https://192.168.5.100/file.tar.gz 
&& tar xvf -C file.tar.gz /opt/ 
&& rm file.tar.gz
Use comments
● Comments can help users as well as yourself in the future.
● Dockerfile comments start with ‘#’
● Eg:
#Install required packages for the app
RUN apt-get install package1 package2 package3
# Modifying texts from default config
RUN sed -i ‘s/word1/word2/g’ config.cfg
ADD & COPY
● COPY only copies file from directory
● ADD allows source to be URL
● ADD also has functionality of `tar`, archiving
● Use COPY as far as possible as it is more transparent.
● ADD may add malicious files from unknown sources if used
improperly.
References
● Dockerfile references
https://docs.docker.com/engine/reference/builder/
● 10 things to avoid in docker containers
https://developers.redhat.com/blog/2016/02/24/10-things-to-avoid-in-d
● Docker best practices
https://github.com/FuriKuri/docker-best-practices
avasz@protonmail.com
Ad

More Related Content

What's hot (20)

openSUSE Conference 2017 - YaST News
openSUSE Conference 2017 - YaST NewsopenSUSE Conference 2017 - YaST News
openSUSE Conference 2017 - YaST News
lslezak
 
Anton Cherednikov "Modules and Artifacts in NPM"
Anton Cherednikov "Modules and Artifacts in NPM"Anton Cherednikov "Modules and Artifacts in NPM"
Anton Cherednikov "Modules and Artifacts in NPM"
LogeekNightUkraine
 
OpenCms Days 2013 - Gradle based OpenCms build automated setup
OpenCms Days 2013 - Gradle based OpenCms build automated setupOpenCms Days 2013 - Gradle based OpenCms build automated setup
OpenCms Days 2013 - Gradle based OpenCms build automated setup
Alkacon Software GmbH & Co. KG
 
Laka Blogging engine
Laka Blogging engineLaka Blogging engine
Laka Blogging engine
Amitoj Singh
 
Docker session II: Introduction to Docker
Docker session II: Introduction to DockerDocker session II: Introduction to Docker
Docker session II: Introduction to Docker
Degendra Sivakoti
 
From Docker Run To Docker Compose
From Docker Run To Docker ComposeFrom Docker Run To Docker Compose
From Docker Run To Docker Compose
Fitra Aditya
 
Docker e git lab
Docker e git labDocker e git lab
Docker e git lab
Gianluca Padovani
 
OpenCmsDays 2013 - Using OpenCms 9 folders as a network drive
OpenCmsDays 2013 - Using OpenCms 9 folders as a network driveOpenCmsDays 2013 - Using OpenCms 9 folders as a network drive
OpenCmsDays 2013 - Using OpenCms 9 folders as a network drive
Alkacon Software GmbH & Co. KG
 
Boston Code Dojo - Docker meetup slides
Boston Code Dojo - Docker meetup slidesBoston Code Dojo - Docker meetup slides
Boston Code Dojo - Docker meetup slides
Calvin Froedge
 
Headless approach and Acquia - Case study - Chris Ozog
Headless approach and Acquia - Case study - Chris OzogHeadless approach and Acquia - Case study - Chris Ozog
Headless approach and Acquia - Case study - Chris Ozog
DrupalCamp Kyiv
 
Composer
ComposerComposer
Composer
Naseer Ahmad
 
GDG Lima - Docker Compose
GDG Lima - Docker ComposeGDG Lima - Docker Compose
GDG Lima - Docker Compose
Mario IC
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
Anvay Patil
 
Wt vs phalcon
Wt vs phalconWt vs phalcon
Wt vs phalcon
Amitoj Singh
 
Docker compose
Docker composeDocker compose
Docker compose
Felipe Ruhland
 
OpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with GradleOpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with Gradle
Alkacon Software GmbH & Co. KG
 
Dockerfile for rust project
Dockerfile for rust projectDockerfile for rust project
Dockerfile for rust project
Hien Nguyen
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
sparkfabrik
 
Docker. Micro services for lazy developers
Docker. Micro services for lazy developersDocker. Micro services for lazy developers
Docker. Micro services for lazy developers
Eugene Krevenets
 
Meetup 05 27-2015
Meetup   05 27-2015Meetup   05 27-2015
Meetup 05 27-2015
Ranjan Parthasarathy
 
openSUSE Conference 2017 - YaST News
openSUSE Conference 2017 - YaST NewsopenSUSE Conference 2017 - YaST News
openSUSE Conference 2017 - YaST News
lslezak
 
Anton Cherednikov "Modules and Artifacts in NPM"
Anton Cherednikov "Modules and Artifacts in NPM"Anton Cherednikov "Modules and Artifacts in NPM"
Anton Cherednikov "Modules and Artifacts in NPM"
LogeekNightUkraine
 
OpenCms Days 2013 - Gradle based OpenCms build automated setup
OpenCms Days 2013 - Gradle based OpenCms build automated setupOpenCms Days 2013 - Gradle based OpenCms build automated setup
OpenCms Days 2013 - Gradle based OpenCms build automated setup
Alkacon Software GmbH & Co. KG
 
Laka Blogging engine
Laka Blogging engineLaka Blogging engine
Laka Blogging engine
Amitoj Singh
 
Docker session II: Introduction to Docker
Docker session II: Introduction to DockerDocker session II: Introduction to Docker
Docker session II: Introduction to Docker
Degendra Sivakoti
 
From Docker Run To Docker Compose
From Docker Run To Docker ComposeFrom Docker Run To Docker Compose
From Docker Run To Docker Compose
Fitra Aditya
 
OpenCmsDays 2013 - Using OpenCms 9 folders as a network drive
OpenCmsDays 2013 - Using OpenCms 9 folders as a network driveOpenCmsDays 2013 - Using OpenCms 9 folders as a network drive
OpenCmsDays 2013 - Using OpenCms 9 folders as a network drive
Alkacon Software GmbH & Co. KG
 
Boston Code Dojo - Docker meetup slides
Boston Code Dojo - Docker meetup slidesBoston Code Dojo - Docker meetup slides
Boston Code Dojo - Docker meetup slides
Calvin Froedge
 
Headless approach and Acquia - Case study - Chris Ozog
Headless approach and Acquia - Case study - Chris OzogHeadless approach and Acquia - Case study - Chris Ozog
Headless approach and Acquia - Case study - Chris Ozog
DrupalCamp Kyiv
 
GDG Lima - Docker Compose
GDG Lima - Docker ComposeGDG Lima - Docker Compose
GDG Lima - Docker Compose
Mario IC
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
Anvay Patil
 
Dockerfile for rust project
Dockerfile for rust projectDockerfile for rust project
Dockerfile for rust project
Hien Nguyen
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
sparkfabrik
 
Docker. Micro services for lazy developers
Docker. Micro services for lazy developersDocker. Micro services for lazy developers
Docker. Micro services for lazy developers
Eugene Krevenets
 

Viewers also liked (20)

Inverse Trigonometric Functions
Inverse Trigonometric FunctionsInverse Trigonometric Functions
Inverse Trigonometric Functions
Sadiq Hussain
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
Leslie Samuel
 
Acertijo de rompecabezas para la enseñanza de las ciencias (MTRO. JAVIER SOLI...
Acertijo de rompecabezas para la enseñanza de las ciencias (MTRO. JAVIER SOLI...Acertijo de rompecabezas para la enseñanza de las ciencias (MTRO. JAVIER SOLI...
Acertijo de rompecabezas para la enseñanza de las ciencias (MTRO. JAVIER SOLI...
JAVIER SOLIS NOYOLA
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of Work
Volker Hirsch
 
2016.1.25
2016.1.252016.1.25
2016.1.25
Surit Aryal
 
GDC17 VFX Bootcamp参加報告
GDC17 VFX Bootcamp参加報告GDC17 VFX Bootcamp参加報告
GDC17 VFX Bootcamp参加報告
Makoto Goto
 
FRJ2017 デジタルファンドレイジング最前線 セッション発表資料
FRJ2017 デジタルファンドレイジング最前線 セッション発表資料FRJ2017 デジタルファンドレイジング最前線 セッション発表資料
FRJ2017 デジタルファンドレイジング最前線 セッション発表資料
株式会社カルミナ(Carmina Inc.)
 
You Are Not As Rational As You Think
You Are Not As Rational As You ThinkYou Are Not As Rational As You Think
You Are Not As Rational As You Think
Yang Ao Wei 楊翱維
 
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 20173 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017
Drift
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
Natasha Murashev
 
開發學校雲端服務的奇技淫巧(Tips for Building Third-Party School Service)
開發學校雲端服務的奇技淫巧(Tips for Building  Third-Party School Service)開發學校雲端服務的奇技淫巧(Tips for Building  Third-Party School Service)
開發學校雲端服務的奇技淫巧(Tips for Building Third-Party School Service)
Sheng-Hao Ma
 
Docker bday #4 intro deck
Docker bday #4   intro deckDocker bday #4   intro deck
Docker bday #4 intro deck
Surit Aryal
 
Nana moraes
Nana moraesNana moraes
Nana moraes
Lucas Rodrigues
 
Python으로 채팅 구현하기
Python으로 채팅 구현하기Python으로 채팅 구현하기
Python으로 채팅 구현하기
Tae Young Lee
 
Ppp sobre publisher
Ppp sobre publisherPpp sobre publisher
Ppp sobre publisher
Marielis Roberti
 
Is Bevan's NHS under threat?
Is Bevan's NHS under threat?Is Bevan's NHS under threat?
Is Bevan's NHS under threat?
Geraint Day
 
Api days 2014 from theatrophone to ap is_the 2020 telco challenge_
Api days 2014  from theatrophone to ap is_the 2020 telco challenge_Api days 2014  from theatrophone to ap is_the 2020 telco challenge_
Api days 2014 from theatrophone to ap is_the 2020 telco challenge_
Luis Borges Quina
 
Pardot presentation
Pardot presentationPardot presentation
Pardot presentation
Nitin Gupta ☁
 
Clara Cleymans koos meisjesnaam als benaming voor haar firma
Clara Cleymans koos meisjesnaam als benaming voor haar firmaClara Cleymans koos meisjesnaam als benaming voor haar firma
Clara Cleymans koos meisjesnaam als benaming voor haar firma
Thierry Debels
 
Marina gascon la prueba judicial
Marina gascon   la prueba judicialMarina gascon   la prueba judicial
Marina gascon la prueba judicial
Mirta Hnriquez
 
Inverse Trigonometric Functions
Inverse Trigonometric FunctionsInverse Trigonometric Functions
Inverse Trigonometric Functions
Sadiq Hussain
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
Leslie Samuel
 
Acertijo de rompecabezas para la enseñanza de las ciencias (MTRO. JAVIER SOLI...
Acertijo de rompecabezas para la enseñanza de las ciencias (MTRO. JAVIER SOLI...Acertijo de rompecabezas para la enseñanza de las ciencias (MTRO. JAVIER SOLI...
Acertijo de rompecabezas para la enseñanza de las ciencias (MTRO. JAVIER SOLI...
JAVIER SOLIS NOYOLA
 
TEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of WorkTEDx Manchester: AI & The Future of Work
TEDx Manchester: AI & The Future of Work
Volker Hirsch
 
GDC17 VFX Bootcamp参加報告
GDC17 VFX Bootcamp参加報告GDC17 VFX Bootcamp参加報告
GDC17 VFX Bootcamp参加報告
Makoto Goto
 
FRJ2017 デジタルファンドレイジング最前線 セッション発表資料
FRJ2017 デジタルファンドレイジング最前線 セッション発表資料FRJ2017 デジタルファンドレイジング最前線 セッション発表資料
FRJ2017 デジタルファンドレイジング最前線 セッション発表資料
株式会社カルミナ(Carmina Inc.)
 
You Are Not As Rational As You Think
You Are Not As Rational As You ThinkYou Are Not As Rational As You Think
You Are Not As Rational As You Think
Yang Ao Wei 楊翱維
 
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 20173 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017
Drift
 
開發學校雲端服務的奇技淫巧(Tips for Building Third-Party School Service)
開發學校雲端服務的奇技淫巧(Tips for Building  Third-Party School Service)開發學校雲端服務的奇技淫巧(Tips for Building  Third-Party School Service)
開發學校雲端服務的奇技淫巧(Tips for Building Third-Party School Service)
Sheng-Hao Ma
 
Docker bday #4 intro deck
Docker bday #4   intro deckDocker bday #4   intro deck
Docker bday #4 intro deck
Surit Aryal
 
Python으로 채팅 구현하기
Python으로 채팅 구현하기Python으로 채팅 구현하기
Python으로 채팅 구현하기
Tae Young Lee
 
Is Bevan's NHS under threat?
Is Bevan's NHS under threat?Is Bevan's NHS under threat?
Is Bevan's NHS under threat?
Geraint Day
 
Api days 2014 from theatrophone to ap is_the 2020 telco challenge_
Api days 2014  from theatrophone to ap is_the 2020 telco challenge_Api days 2014  from theatrophone to ap is_the 2020 telco challenge_
Api days 2014 from theatrophone to ap is_the 2020 telco challenge_
Luis Borges Quina
 
Clara Cleymans koos meisjesnaam als benaming voor haar firma
Clara Cleymans koos meisjesnaam als benaming voor haar firmaClara Cleymans koos meisjesnaam als benaming voor haar firma
Clara Cleymans koos meisjesnaam als benaming voor haar firma
Thierry Debels
 
Marina gascon la prueba judicial
Marina gascon   la prueba judicialMarina gascon   la prueba judicial
Marina gascon la prueba judicial
Mirta Hnriquez
 
Ad

Similar to Dockerfiles & Best Practices (20)

Docker 101
Docker 101Docker 101
Docker 101
Hung-Che Lo
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
Samuel Chow
 
Getting started with docker (2017)
Getting started with docker (2017)Getting started with docker (2017)
Getting started with docker (2017)
JEMLI Fathi
 
Docker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los AngelesDocker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los Angeles
Jérôme Petazzoni
 
Introduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxDataIntroduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxData
InfluxData
 
Best Practices for Developing & Deploying Java Applications with Docker
Best Practices for Developing & Deploying Java Applications with DockerBest Practices for Developing & Deploying Java Applications with Docker
Best Practices for Developing & Deploying Java Applications with Docker
Eric Smalling
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
DrupalDay
 
Introduction to Docker and Containers
Introduction to Docker and ContainersIntroduction to Docker and Containers
Introduction to Docker and Containers
Docker, Inc.
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with Docker
Geeta Vinnakota
 
Docker up and Running For Web Developers
Docker up and Running For Web DevelopersDocker up and Running For Web Developers
Docker up and Running For Web Developers
BADR
 
Docker Up and Running for Web Developers
Docker Up and Running for Web DevelopersDocker Up and Running for Web Developers
Docker Up and Running for Web Developers
Amr Fawzy
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
Hiroki Endo
 
Docker+java
Docker+javaDocker+java
Docker+java
DPC Consulting Ltd
 
Getting Started with Docker
Getting Started with Docker Getting Started with Docker
Getting Started with Docker
Anup Segu
 
Introduction to containers
Introduction to containersIntroduction to containers
Introduction to containers
Nitish Jadia
 
Introduction to Docker storage, volume and image
Introduction to Docker storage, volume and imageIntroduction to Docker storage, volume and image
Introduction to Docker storage, volume and image
ejlp12
 
Super powered Drupal development with docker
Super powered Drupal development with dockerSuper powered Drupal development with docker
Super powered Drupal development with docker
Maciej Lukianski
 
Docker on Power Systems
Docker on Power SystemsDocker on Power Systems
Docker on Power Systems
Cesar Maciel
 
Introduction of Docker and Docker Compose
Introduction of Docker and Docker ComposeIntroduction of Docker and Docker Compose
Introduction of Docker and Docker Compose
Dr. Ketan Parmar
 
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3 Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
Puppet
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
Samuel Chow
 
Getting started with docker (2017)
Getting started with docker (2017)Getting started with docker (2017)
Getting started with docker (2017)
JEMLI Fathi
 
Docker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los AngelesDocker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los Angeles
Jérôme Petazzoni
 
Introduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxDataIntroduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxData
InfluxData
 
Best Practices for Developing & Deploying Java Applications with Docker
Best Practices for Developing & Deploying Java Applications with DockerBest Practices for Developing & Deploying Java Applications with Docker
Best Practices for Developing & Deploying Java Applications with Docker
Eric Smalling
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
DrupalDay
 
Introduction to Docker and Containers
Introduction to Docker and ContainersIntroduction to Docker and Containers
Introduction to Docker and Containers
Docker, Inc.
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with Docker
Geeta Vinnakota
 
Docker up and Running For Web Developers
Docker up and Running For Web DevelopersDocker up and Running For Web Developers
Docker up and Running For Web Developers
BADR
 
Docker Up and Running for Web Developers
Docker Up and Running for Web DevelopersDocker Up and Running for Web Developers
Docker Up and Running for Web Developers
Amr Fawzy
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
Hiroki Endo
 
Getting Started with Docker
Getting Started with Docker Getting Started with Docker
Getting Started with Docker
Anup Segu
 
Introduction to containers
Introduction to containersIntroduction to containers
Introduction to containers
Nitish Jadia
 
Introduction to Docker storage, volume and image
Introduction to Docker storage, volume and imageIntroduction to Docker storage, volume and image
Introduction to Docker storage, volume and image
ejlp12
 
Super powered Drupal development with docker
Super powered Drupal development with dockerSuper powered Drupal development with docker
Super powered Drupal development with docker
Maciej Lukianski
 
Docker on Power Systems
Docker on Power SystemsDocker on Power Systems
Docker on Power Systems
Cesar Maciel
 
Introduction of Docker and Docker Compose
Introduction of Docker and Docker ComposeIntroduction of Docker and Docker Compose
Introduction of Docker and Docker Compose
Dr. Ketan Parmar
 
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3 Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
Puppet
 
Ad

Recently uploaded (20)

TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 

Dockerfiles & Best Practices

  • 1. Dockerfiles & Best Practices #BDay4
  • 2. Avash Mulmi ● Mozilla Representative for Nepal ● Volunteer, FOSS Nepal Community ● Docker Meetup Organizer
  • 3. Agenda ● What are Dockerfiles? ● Usage ● Best Practices
  • 4. Dockerfile(s)? ● Textfile, named Dockerfile ● Contains commands, in sequential order ● Used to build an image ● Have own format and instruction set
  • 7. Building Images ● Change WORKDIR to Folder with Dockerfile (General Practice) ● ~# docker build . ● ~# docker build -t IMAGE_NAME:Tag . ● ~# docker build -t IMAGE_NAME:Tag -f Dockerfile /path/to/Dockerfile
  • 8. Working with Built Image ● Check for built image:  ~# docker images ● Saving built image:  ~# docker save IMAGENAME > image.tar ● Deleting/Removing built image:  ~# docker rmi IMAGENAME  ~# docker rmi IMAGE_ID
  • 9. Best Practices ● Ephemeral Containers ● Using .dockerignore file ● As lightweight as possible ● Minimize the number of layers ● One container, One purpose ● Use volumes ● Avoid using root user
  • 10. Ephemeral Containers ● Containers should be ephemeral ● Literal meaning of Ephemeral → Short lived, brief, momentary ● Stopped, Destroyed and New one built with minimum set-up & configurations ● Good and Complete Dockerfile can achieve this easily
  • 11. .dockerignore ● Similar to .gitignore ● Generally Dockerfile is in an empty directory ● In some cases, we need to add files and directories to the containers ● In such cases, use .dockerignore in those directories to skip files that are not required at all
  • 12. Lightweight ● Install only required packages ● It can reduce complexity, dependencies, file size and build times ● Some applications ‘might’ look important for future ● For eg: a text editor in a database image ● Make image as small as possible using light base images where possible
  • 13. Minimize Number of Layers ● Each RUN command creates a new layer ● Need to know figure out how to minimize the number of layers ● Example 1: update, upgrade and installation of packages can stay in a single RUN command with multi-line arguments ● Example 2: download of a zip file, extraction and move to another folder ● Benefits: docker pull and docker push are faster, reduces complexity of an image etc.
  • 14. Example 1 ● RUN apt-get update RUN apt-get install apache2 git mysql-server php5 vim RUN apt-get clean ● RUN apt-get update && apt-get install apache2 git mysql-server php5 vim && apt-get clean
  • 15. Example 2 ● RUN curl http://192.168.100.5/file.tar.gz RUN tar xvf file.tar.gz RUN mv EXTRACTED_FILE /opt/ ● RUN curl http://192.168.100.5/file.tar.gz | tar xvf -C /opt/
  • 16. Example 3 ● RUN apt-get update && apt-get install apache2 git mysql-server php5 vim && apt-get clean RUN curl http://192.168.100.5/file.tar.gz | tar xvf -C /opt/ RUN cp /etc/someconfig /opt/someconfig && ln -s /usr/share/app1/default.cfg /opt/default.cfg ● RUN apt-get update && apt-get install apache2 git mysql-server php5 vim && apt-get clean && curl | tar xvf -C /opt/ && cp /etc/someconfig /opt/someconfig && ln -s /usr/share/app1/default.cfg /opt/default.cfg && cd /opt/ && ./configure && make && make install && rm old_unnecessary_files
  • 17. One Container, One Purpose ● Keep containers as clean and modular as possible ● Creating containers for different dependent applications and linking them makes it easier to maintain & reuse those containers ● Eg: Instead of single container with webserver, database and (php), three separate containers with webserver, database and (php) in each is better. ● Why? → Maintenance & Reusablity
  • 18. Use Volumes ● Do not store data in containers, as far as possible ● Use Volumes to store data ● Concept of ephemeral ● App container running v1.9 should be easily stopped, destroyed and updated with container running v2.0 without losing any data
  • 19. Avoid using `root` user ● By default docker runs containers with root user ● If possible use a normal user ● Depends on situation
  • 20. Delete unnecessary files ● Reduces size of image and container ● Eg: RUN curl https://192.168.5.100/file.tar.gz && tar xvf -C file.tar.gz /opt/ && rm file.tar.gz
  • 21. Use comments ● Comments can help users as well as yourself in the future. ● Dockerfile comments start with ‘#’ ● Eg: #Install required packages for the app RUN apt-get install package1 package2 package3 # Modifying texts from default config RUN sed -i ‘s/word1/word2/g’ config.cfg
  • 22. ADD & COPY ● COPY only copies file from directory ● ADD allows source to be URL ● ADD also has functionality of `tar`, archiving ● Use COPY as far as possible as it is more transparent. ● ADD may add malicious files from unknown sources if used improperly.
  • 23. References ● Dockerfile references https://docs.docker.com/engine/reference/builder/ ● 10 things to avoid in docker containers https://developers.redhat.com/blog/2016/02/24/10-things-to-avoid-in-d ● Docker best practices https://github.com/FuriKuri/docker-best-practices