SlideShare a Scribd company logo
1 of 17
Download to read offline
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

What's hot

Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...
Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...
Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...Edureka!
 
Docker: From Zero to Hero
Docker: From Zero to HeroDocker: From Zero to Hero
Docker: From Zero to Herofazalraja
 
Docker Compose by Aanand Prasad
Docker Compose by Aanand Prasad Docker Compose by Aanand Prasad
Docker Compose by Aanand Prasad Docker, Inc.
 
Docker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and ContainersDocker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and ContainersYajushi Srivastava
 
How to write a Dockerfile
How to write a DockerfileHow to write a Dockerfile
How to write a DockerfileKnoldus Inc.
 
Docker introduction
Docker introductionDocker introduction
Docker introductionPhuc Nguyen
 
Docker intro
Docker introDocker intro
Docker introOleg Z
 
Docker introduction (1)
Docker introduction (1)Docker introduction (1)
Docker introduction (1)Gourav Varma
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to DockerAditya Konarde
 
docker installation and basics
docker installation and basicsdocker installation and basics
docker installation and basicsWalid Ashraf
 
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...Simplilearn
 
Docker introduction
Docker introductionDocker introduction
Docker introductiondotCloud
 
Docker introduction & benefits
Docker introduction & benefitsDocker introduction & benefits
Docker introduction & benefitsAmit Manwade
 

What's hot (20)

presentation on Docker
presentation on Dockerpresentation on Docker
presentation on Docker
 
Docker
DockerDocker
Docker
 
Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...
Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...
Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...
 
Docker: From Zero to Hero
Docker: From Zero to HeroDocker: From Zero to Hero
Docker: From Zero to Hero
 
Docker Compose by Aanand Prasad
Docker Compose by Aanand Prasad Docker Compose by Aanand Prasad
Docker Compose by Aanand Prasad
 
Docker.pptx
Docker.pptxDocker.pptx
Docker.pptx
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
 
What is Docker
What is DockerWhat is Docker
What is Docker
 
Docker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and ContainersDocker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and Containers
 
Introduction to container based virtualization with docker
Introduction to container based virtualization with dockerIntroduction to container based virtualization with docker
Introduction to container based virtualization with docker
 
How to write a Dockerfile
How to write a DockerfileHow to write a Dockerfile
How to write a Dockerfile
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
Docker intro
Docker introDocker intro
Docker intro
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
 
Docker introduction (1)
Docker introduction (1)Docker introduction (1)
Docker introduction (1)
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
docker installation and basics
docker installation and basicsdocker installation and basics
docker installation and basics
 
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
Docker introduction & benefits
Docker introduction & benefitsDocker introduction & benefits
Docker introduction & benefits
 

Viewers also liked

Seminario: Docker y su Ecosistema
Seminario: Docker y su EcosistemaSeminario: Docker y su Ecosistema
Seminario: Docker y su EcosistemaGermán Moltó
 
Introducción a Docker
Introducción a DockerIntroducción a Docker
Introducción a DockerOpen Canarias
 
Introduccion a SQL Server 2017 en Docker
Introduccion a SQL Server 2017 en Docker Introduccion a SQL Server 2017 en Docker
Introduccion a SQL Server 2017 en Docker Eduardo Castro
 
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...E. Camden Fisher
 

Viewers also liked (7)

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

Similar to Dockerfile Deep Dive Creating Images

Getting started with Docker
Getting started with DockerGetting started with Docker
Getting started with DockerRavindu Fernando
 
[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101Naukri.com
 
Up and running with docker
Up and running with dockerUp and running with docker
Up and running with dockerMichelle Liu
 
Docker 101 Workshop slides (JavaOne 2017)
Docker 101 Workshop slides (JavaOne 2017)Docker 101 Workshop slides (JavaOne 2017)
Docker 101 Workshop slides (JavaOne 2017)Eric Smalling
 
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Binary Studio
 
Docker in a JS Developer’s Life
Docker in a JS Developer’s LifeDocker in a JS Developer’s Life
Docker in a JS Developer’s LifeGlobalLogic Ukraine
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to DockerKuan Yen Heng
 
Virtualization, Containers, Docker and scalable container management services
Virtualization, Containers, Docker and scalable container management servicesVirtualization, Containers, Docker and scalable container management services
Virtualization, Containers, Docker and scalable container management servicesabhishek chawla
 
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Binary Studio
 
Optimizing Docker Images
Optimizing Docker ImagesOptimizing Docker Images
Optimizing Docker ImagesBrian DeHamer
 

Similar to Dockerfile Deep Dive Creating Images (20)

Getting started with Docker
Getting started with DockerGetting started with Docker
Getting started with Docker
 
Docker @ Atlogys
Docker @ AtlogysDocker @ Atlogys
Docker @ Atlogys
 
[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101
 
Up and running with docker
Up and running with dockerUp and running with docker
Up and running with docker
 
Docker.pdf
Docker.pdfDocker.pdf
Docker.pdf
 
Docker
DockerDocker
Docker
 
Docker 101 Workshop slides (JavaOne 2017)
Docker 101 Workshop slides (JavaOne 2017)Docker 101 Workshop slides (JavaOne 2017)
Docker 101 Workshop slides (JavaOne 2017)
 
docker.pdf
docker.pdfdocker.pdf
docker.pdf
 
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2
 
Docker in a JS Developer’s Life
Docker in a JS Developer’s LifeDocker in a JS Developer’s Life
Docker in a JS Developer’s Life
 
Docker Kubernetes Istio
Docker Kubernetes IstioDocker Kubernetes Istio
Docker Kubernetes Istio
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Containerization using docker and its applications
Containerization using docker and its applicationsContainerization using docker and its applications
Containerization using docker and its applications
 
Containerization using docker and its applications
Containerization using docker and its applicationsContainerization using docker and its applications
Containerization using docker and its applications
 
Virtualization, Containers, Docker and scalable container management services
Virtualization, Containers, Docker and scalable container management servicesVirtualization, Containers, Docker and scalable container management services
Virtualization, Containers, Docker and scalable container management services
 
Docker introduction - Part 1
Docker introduction - Part 1Docker introduction - Part 1
Docker introduction - Part 1
 
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2
 
Docker
DockerDocker
Docker
 
Optimizing Docker Images
Optimizing Docker ImagesOptimizing Docker Images
Optimizing Docker Images
 
Docker From Scratch
Docker From ScratchDocker From Scratch
Docker From Scratch
 

Recently uploaded

Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 

Recently uploaded (20)

Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 

Dockerfile Deep Dive Creating Images

  • 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/