SlideShare uma empresa Scribd logo
1 de 24
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

Mais conteúdo relacionado

Mais procurados

openSUSE Conference 2017 - YaST News
openSUSE Conference 2017 - YaST NewsopenSUSE Conference 2017 - YaST News
openSUSE Conference 2017 - YaST Newslslezak
 
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 setupAlkacon Software GmbH & Co. KG
 
Laka Blogging engine
Laka Blogging engineLaka Blogging engine
Laka Blogging engineAmitoj Singh
 
Docker session II: Introduction to Docker
Docker session II: Introduction to DockerDocker session II: Introduction to Docker
Docker session II: Introduction to DockerDegendra Sivakoti
 
From Docker Run To Docker Compose
From Docker Run To Docker ComposeFrom Docker Run To Docker Compose
From Docker Run To Docker ComposeFitra 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 driveAlkacon 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 slidesCalvin 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 OzogDrupalCamp Kyiv
 
GDG Lima - Docker Compose
GDG Lima - Docker ComposeGDG Lima - Docker Compose
GDG Lima - Docker ComposeMario IC
 
Docker for developers
Docker for developersDocker for developers
Docker for developersAnvay Patil
 
Dockerfile for rust project
Dockerfile for rust projectDockerfile for rust project
Dockerfile for rust projectHien Nguyen
 
Docker for developers
Docker for developersDocker for developers
Docker for developerssparkfabrik
 
Docker. Micro services for lazy developers
Docker. Micro services for lazy developersDocker. Micro services for lazy developers
Docker. Micro services for lazy developersEugene Krevenets
 

Mais procurados (20)

openSUSE Conference 2017 - YaST News
openSUSE Conference 2017 - YaST NewsopenSUSE Conference 2017 - YaST News
openSUSE Conference 2017 - YaST News
 
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"
 
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
 
Laka Blogging engine
Laka Blogging engineLaka Blogging engine
Laka Blogging engine
 
Docker session II: Introduction to Docker
Docker session II: Introduction to DockerDocker session II: Introduction to Docker
Docker session II: Introduction to Docker
 
From Docker Run To Docker Compose
From Docker Run To Docker ComposeFrom Docker Run To Docker Compose
From Docker Run To Docker Compose
 
Docker e git lab
Docker e git labDocker e git lab
Docker e git lab
 
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
 
Boston Code Dojo - Docker meetup slides
Boston Code Dojo - Docker meetup slidesBoston Code Dojo - Docker meetup slides
Boston Code Dojo - Docker meetup slides
 
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
 
Composer
ComposerComposer
Composer
 
GDG Lima - Docker Compose
GDG Lima - Docker ComposeGDG Lima - Docker Compose
GDG Lima - Docker Compose
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
 
Wt vs phalcon
Wt vs phalconWt vs phalcon
Wt vs phalcon
 
Docker compose
Docker composeDocker compose
Docker compose
 
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
 
Dockerfile for rust project
Dockerfile for rust projectDockerfile for rust project
Dockerfile for rust project
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
 
Docker. Micro services for lazy developers
Docker. Micro services for lazy developersDocker. Micro services for lazy developers
Docker. Micro services for lazy developers
 
Meetup 05 27-2015
Meetup   05 27-2015Meetup   05 27-2015
Meetup 05 27-2015
 

Destaque

Inverse Trigonometric Functions
Inverse Trigonometric FunctionsInverse Trigonometric Functions
Inverse Trigonometric FunctionsSadiq 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 NicheLeslie 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 WorkVolker 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 ThinkYang 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 2017Drift
 
開發學校雲端服務的奇技淫巧(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 deckSurit 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 firmaThierry Debels
 
Marina gascon la prueba judicial
Marina gascon   la prueba judicialMarina gascon   la prueba judicial
Marina gascon la prueba judicialMirta Hnriquez
 

Destaque (20)

Inverse Trigonometric Functions
Inverse Trigonometric FunctionsInverse Trigonometric Functions
Inverse Trigonometric Functions
 
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
 
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...
 
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
 
2016.1.25
2016.1.252016.1.25
2016.1.25
 
GDC17 VFX Bootcamp参加報告
GDC17 VFX Bootcamp参加報告GDC17 VFX Bootcamp参加報告
GDC17 VFX Bootcamp参加報告
 
FRJ2017 デジタルファンドレイジング最前線 セッション発表資料
FRJ2017 デジタルファンドレイジング最前線 セッション発表資料FRJ2017 デジタルファンドレイジング最前線 セッション発表資料
FRJ2017 デジタルファンドレイジング最前線 セッション発表資料
 
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
 
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
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
 
開發學校雲端服務的奇技淫巧(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)
 
Docker bday #4 intro deck
Docker bday #4   intro deckDocker bday #4   intro deck
Docker bday #4 intro deck
 
Nana moraes
Nana moraesNana moraes
Nana moraes
 
Python으로 채팅 구현하기
Python으로 채팅 구현하기Python으로 채팅 구현하기
Python으로 채팅 구현하기
 
Ppp sobre publisher
Ppp sobre publisherPpp sobre publisher
Ppp sobre publisher
 
Is Bevan's NHS under threat?
Is Bevan's NHS under threat?Is Bevan's NHS under threat?
Is Bevan's NHS under threat?
 
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_
 
Pardot presentation
Pardot presentationPardot presentation
Pardot presentation
 
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
 
Marina gascon la prueba judicial
Marina gascon   la prueba judicialMarina gascon   la prueba judicial
Marina gascon la prueba judicial
 

Semelhante a Dockerfiles & Best Practices

Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tipsSamuel 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 AngelesJé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 InfluxDataInfluxData
 
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 DockerEric Smalling
 
Docker for developers
Docker for developersDocker for developers
Docker for developersDrupalDay
 
Introduction to Docker and Containers
Introduction to Docker and ContainersIntroduction to Docker and Containers
Introduction to Docker and ContainersDocker, Inc.
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with DockerGeeta 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 DevelopersBADR
 
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 DevelopersAmr Fawzy
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to dockerHiroki 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 containersNitish 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 imageejlp12
 
Super powered Drupal development with docker
Super powered Drupal development with dockerSuper powered Drupal development with docker
Super powered Drupal development with dockerMaciej Lukianski
 
Docker on Power Systems
Docker on Power SystemsDocker on Power Systems
Docker on Power SystemsCesar Maciel
 
Introduction of Docker and Docker Compose
Introduction of Docker and Docker ComposeIntroduction of Docker and Docker Compose
Introduction of Docker and Docker ComposeDr. 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
 

Semelhante a Dockerfiles & Best Practices (20)

Docker 101
Docker 101Docker 101
Docker 101
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
 
Getting started with docker (2017)
Getting started with docker (2017)Getting started with docker (2017)
Getting started with docker (2017)
 
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
 
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
 
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
 
Docker for developers
Docker for developersDocker for developers
Docker for developers
 
Introduction to Docker and Containers
Introduction to Docker and ContainersIntroduction to Docker and Containers
Introduction to Docker and Containers
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with Docker
 
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
 
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
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
Docker+java
Docker+javaDocker+java
Docker+java
 
Getting Started with Docker
Getting Started with Docker Getting Started with Docker
Getting Started with Docker
 
Introduction to containers
Introduction to containersIntroduction to containers
Introduction to containers
 
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
 
Super powered Drupal development with docker
Super powered Drupal development with dockerSuper powered Drupal development with docker
Super powered Drupal development with docker
 
Docker on Power Systems
Docker on Power SystemsDocker on Power Systems
Docker on Power Systems
 
Introduction of Docker and Docker Compose
Introduction of Docker and Docker ComposeIntroduction of Docker and Docker Compose
Introduction of Docker and Docker Compose
 
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
 

Último

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Último (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

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