SlideShare a Scribd company logo
5
Most read
15
Most read
17
Most read
Docker Deep Dive
Creating Images with Dockerfiles
Dockerfile Basics
• Docker Images are built from a
base image.
• Base Images are built up using
simple instructions such as
• Run a command.
• Add a file or directory.
• Create an environment
variable.
• What process to run when
launching a container from
this image.
Docker Images
• Docker images are read
only templates from
which containers are
launched from
• Each image consists of
a series of layers using
the union file system
• When you change an
image a new layer is
created.
FROM
the FROM instruction sets the Base Image
for subsequent instructions. As such, a valid
Dockerfile must have FROM as its first
instruction. The image can be any valid
image – it is especially easy to start by
pulling an image from the Public
Repositories.



FROM java:8-jre
ENV
The ENV instruction is also useful for
providing required environment variables
specific to services you wish to containerize,
such as Postgres’s PGDATA.



ENV TOMCAT_MAJOR 8

ENV TOMCAT_VERSION 8.0.26
RUN
The RUN instruction will execute any commands in a new
layer on top of the current image and commit the results.
The resulting committed image will be used for the next
step in the Dockerfile.
RUN apt-get update && apt-get install -y 
bzr 
cvs 
git 
mercurial 
subversion
ADD and Copy
The Add and Copy commands can be used to add files to
the container.
•For Add if source file is a tar file the file will be extracted.
•Add allows source file to be a URL
•Use a trailing slash to indicate a directory vs a file.
COPY hom* /mydir/ # adds all files starting with "hom"
COPY hom?.txt /mydir/ # ? is replaced with any single character
EXPOSE
The EXPOSE instructions informs Docker that the container
will listen on the specified network ports at runtime. Docker
uses this information to interconnect containers using links
(see the Docker User Guide) and to determine which ports to
expose to the host when using the -P flag.



EXPOSE 8080
The WORKDIR instruction sets the working directory for any
RUN, CMD, ENTRYPOINT, COPY and ADD instructions that
follow it in the Dockerfile.
It can be used multiple times in the one Dockerfile. If a
relative path is provided, it will be relative to the path of the
previous WORKDIR instruction.
WORKDIR $CATALINA_HOME
WORKDIR
The main purpose of a CMD is to provide defaults for an
executing container.
Can be overridden with arguments to docker run
CMD ["catalina.sh", "run"]
CMD
Building an Image
A Dockerfile that contains a set of instructions that tell
Docker how to build our image. The Dockerfile can be used
to generate an image stored on your local system.
Docker daemon does actual build process. Contents of
current context (folder) is sent to the daemon. Reduce build
overhead by using .dockerignore files.
Each Instruction creates a new layer in the image. The cache
from previous builds is used as much as possible.
docker build -t jellin/tamr:v2 .
Deploying an Image
In order to share your image you can push it to a Docker
Repository. Images can then be pulled from another host.
• Use the internal docker registry for private images.
• Use Docker Hub for public images.
docker tag jellin/tamr:v2 fe-build.tamrfield.com:jellin/tamr:v2
docker push fe-build:jellin/tamr:v2
docker pull fe-build:jellin/tamr:v2
Show some Examples
• Docker volumes are containers for data.
• Can be shared between containers
• Can be mapped to specific directories on the host.
• By Default removing the container does not remove
the volume. (can lead to disk wastage due to
orphaning volumes)
• Data outside of a volume is kept in the union file
system and is lost when the container is deleted.
A Word on Volumes
Dockerfile Best Practices
• use .dockerignore to avoid adding
unnecessary files to your image
• Don’t run apt-update on a single line. This will
cause caching issues if the referenced archive
gets updated, which will make your
subsequent apt-get install fail without
comment.
• Avoid installing unecessary packages
• Always use version tags in FROM
statements. Avoid :latest
• Avoid run + commit, use a Dockerfile
instead
• Installing ssh into a container is not clever
• One Process per container
• Leverage and understand the cache
References
• Dockerfile Best Practices

https://docs.docker.com/articles/
dockerfile_best-practices/

More Related Content

PDF
How to write a Dockerfile
PDF
Introduction to Docker storage, volume and image
PPTX
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
PPTX
What is Docker
PPTX
Docker intro
PDF
Docker Introduction
PDF
Introduction to Docker - VIT Campus
PPTX
Introduction to Docker
How to write a Dockerfile
Introduction to Docker storage, volume and image
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
What is Docker
Docker intro
Docker Introduction
Introduction to Docker - VIT Campus
Introduction to Docker

What's hot (20)

PPTX
Docker introduction for the beginners
PPTX
Docker Networking Overview
PDF
Docker Introduction
PPTX
Docker 101 : Introduction to Docker and Containers
PPTX
Docker 101 - Nov 2016
PDF
Docker 101: Introduction to Docker
PPTX
Getting started with Docker
PPTX
Introduction to Docker - 2017
PPTX
Docker introduction
PPTX
Docker introduction (1)
PPT
presentation on Docker
PDF
Introduction to container based virtualization with docker
PPTX
Virtualization, Containers, Docker and scalable container management services
PPTX
Dockers and containers basics
PDF
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
PPTX
Docker.pptx
PDF
Kubernetes Introduction
PPTX
Kubernetes for Beginners: An Introductory Guide
PDF
Introduction to docker
PDF
Docker & kubernetes
Docker introduction for the beginners
Docker Networking Overview
Docker Introduction
Docker 101 : Introduction to Docker and Containers
Docker 101 - Nov 2016
Docker 101: Introduction to Docker
Getting started with Docker
Introduction to Docker - 2017
Docker introduction
Docker introduction (1)
presentation on Docker
Introduction to container based virtualization with docker
Virtualization, Containers, Docker and scalable container management services
Dockers and containers basics
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
Docker.pptx
Kubernetes Introduction
Kubernetes for Beginners: An Introductory Guide
Introduction to docker
Docker & kubernetes
Ad

Viewers also liked (7)

PDF
Comenzando con Docker en AWS
PDF
Seminario: Docker y su Ecosistema
PDF
Introducción a Docker
PPTX
Introduccion a SQL Server 2017 en Docker
PDF
Contenedores como Servicio con Docker
PPTX
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
PDF
Introduction to Docker
Comenzando con Docker en AWS
Seminario: Docker y su Ecosistema
Introducción a Docker
Introduccion a SQL Server 2017 en Docker
Contenedores como Servicio con Docker
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
Introduction to Docker
Ad

Similar to Dockerfile (20)

PPTX
Getting Started With Docker: Simplifying DevOps
PDF
Getting Started with Docker
PDF
Introduction of Docker and Docker Compose
PDF
Containers + Docker workshop - part 2
PPTX
Docker, LinuX Container
PDF
PPTX
Powercoders · Docker · Fall 2021.pptx
PDF
Docker in a JS Developer’s Life
PDF
Lecture eight to be introduced in class.
PDF
docker.pdf
PPTX
Docker and the Container Ecosystem
PDF
Getting Started with Docker (For Developers)
PPTX
Docker Introductory workshop
PDF
Docker.pdf
PDF
Intro To Docker
PDF
Docker 101 - Intro to Docker
PDF
Docker - Getting Started
PDF
[@NaukriEngineering] Docker 101
PPSX
Docker and containers - Presentation Slides by Priyadarshini Anand
ODP
Dockerfiles & Best Practices
Getting Started With Docker: Simplifying DevOps
Getting Started with Docker
Introduction of Docker and Docker Compose
Containers + Docker workshop - part 2
Docker, LinuX Container
Powercoders · Docker · Fall 2021.pptx
Docker in a JS Developer’s Life
Lecture eight to be introduced in class.
docker.pdf
Docker and the Container Ecosystem
Getting Started with Docker (For Developers)
Docker Introductory workshop
Docker.pdf
Intro To Docker
Docker 101 - Intro to Docker
Docker - Getting Started
[@NaukriEngineering] Docker 101
Docker and containers - Presentation Slides by Priyadarshini Anand
Dockerfiles & Best Practices

Recently uploaded (20)

PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
PDF
REPORT: Heating appliances market in Poland 2024
PDF
Google’s NotebookLM Unveils Video Overviews
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
creating-agentic-ai-solutions-leveraging-aws.pdf
PDF
Dell Pro 14 Plus: Be better prepared for what’s coming
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PDF
ai-archetype-understanding-the-personality-of-agentic-ai.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Belt and Road Supply Chain Finance Blockchain Solution
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
madgavkar20181017ppt McKinsey Presentation.pdf
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Enable Enterprise-Ready Security on IBM i Systems.pdf
REPORT: Heating appliances market in Poland 2024
Google’s NotebookLM Unveils Video Overviews
Transforming Manufacturing operations through Intelligent Integrations
NewMind AI Weekly Chronicles - August'25 Week I
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
creating-agentic-ai-solutions-leveraging-aws.pdf
Dell Pro 14 Plus: Be better prepared for what’s coming
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
ai-archetype-understanding-the-personality-of-agentic-ai.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Belt and Road Supply Chain Finance Blockchain Solution
GamePlan Trading System Review: Professional Trader's Honest Take

Dockerfile

  • 1. Docker Deep Dive Creating Images with Dockerfiles
  • 2. Dockerfile Basics • Docker Images are built from a base image. • Base Images are built up using simple instructions such as • Run a command. • Add a file or directory. • Create an environment variable. • What process to run when launching a container from this image.
  • 3. Docker Images • Docker images are read only templates from which containers are launched from • Each image consists of a series of layers using the union file system • When you change an image a new layer is created.
  • 4. FROM the FROM instruction sets the Base Image for subsequent instructions. As such, a valid Dockerfile must have FROM as its first instruction. The image can be any valid image – it is especially easy to start by pulling an image from the Public Repositories.
 
 FROM java:8-jre
  • 5. ENV The ENV instruction is also useful for providing required environment variables specific to services you wish to containerize, such as Postgres’s PGDATA.
 
 ENV TOMCAT_MAJOR 8
 ENV TOMCAT_VERSION 8.0.26
  • 6. RUN The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile. RUN apt-get update && apt-get install -y bzr cvs git mercurial subversion
  • 7. ADD and Copy The Add and Copy commands can be used to add files to the container. •For Add if source file is a tar file the file will be extracted. •Add allows source file to be a URL •Use a trailing slash to indicate a directory vs a file. COPY hom* /mydir/ # adds all files starting with "hom" COPY hom?.txt /mydir/ # ? is replaced with any single character
  • 8. EXPOSE The EXPOSE instructions informs Docker that the container will listen on the specified network ports at runtime. Docker uses this information to interconnect containers using links (see the Docker User Guide) and to determine which ports to expose to the host when using the -P flag.
 
 EXPOSE 8080
  • 9. The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. It can be used multiple times in the one Dockerfile. If a relative path is provided, it will be relative to the path of the previous WORKDIR instruction. WORKDIR $CATALINA_HOME WORKDIR
  • 10. The main purpose of a CMD is to provide defaults for an executing container. Can be overridden with arguments to docker run CMD ["catalina.sh", "run"] CMD
  • 11. Building an Image A Dockerfile that contains a set of instructions that tell Docker how to build our image. The Dockerfile can be used to generate an image stored on your local system. Docker daemon does actual build process. Contents of current context (folder) is sent to the daemon. Reduce build overhead by using .dockerignore files. Each Instruction creates a new layer in the image. The cache from previous builds is used as much as possible. docker build -t jellin/tamr:v2 .
  • 12. Deploying an Image In order to share your image you can push it to a Docker Repository. Images can then be pulled from another host. • Use the internal docker registry for private images. • Use Docker Hub for public images. docker tag jellin/tamr:v2 fe-build.tamrfield.com:jellin/tamr:v2 docker push fe-build:jellin/tamr:v2 docker pull fe-build:jellin/tamr:v2
  • 14. • Docker volumes are containers for data. • Can be shared between containers • Can be mapped to specific directories on the host. • By Default removing the container does not remove the volume. (can lead to disk wastage due to orphaning volumes) • Data outside of a volume is kept in the union file system and is lost when the container is deleted. A Word on Volumes
  • 15. Dockerfile Best Practices • use .dockerignore to avoid adding unnecessary files to your image • Don’t run apt-update on a single line. This will cause caching issues if the referenced archive gets updated, which will make your subsequent apt-get install fail without comment. • Avoid installing unecessary packages
  • 16. • Always use version tags in FROM statements. Avoid :latest • Avoid run + commit, use a Dockerfile instead • Installing ssh into a container is not clever • One Process per container • Leverage and understand the cache
  • 17. References • Dockerfile Best Practices
 https://docs.docker.com/articles/ dockerfile_best-practices/