SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
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/

Más contenido relacionado

La actualidad más candente

Kubernetes and container security
Kubernetes and container securityKubernetes and container security
Kubernetes and container security
Volodymyr Shynkar
 

La actualidad más candente (20)

Multi Stage Docker Build
Multi Stage Docker Build Multi Stage Docker Build
Multi Stage Docker Build
 
From Zero to Docker
From Zero to DockerFrom Zero to Docker
From Zero to Docker
 
Docker intro
Docker introDocker intro
Docker intro
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
 
Docker Networking Overview
Docker Networking OverviewDocker Networking Overview
Docker Networking Overview
 
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
 
Docker introduction (1)
Docker introduction (1)Docker introduction (1)
Docker introduction (1)
 
Docker Birthday #3 - Intro to Docker Slides
Docker Birthday #3 - Intro to Docker SlidesDocker Birthday #3 - Intro to Docker Slides
Docker Birthday #3 - Intro to Docker Slides
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Kubernetes security
Kubernetes securityKubernetes security
Kubernetes security
 
Docker 101 - Nov 2016
Docker 101 - Nov 2016Docker 101 - Nov 2016
Docker 101 - Nov 2016
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Kubernetes and container security
Kubernetes and container securityKubernetes and container security
Kubernetes and container security
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
DCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best PracticesDCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best Practices
 
Kubernetes Application Deployment with Helm - A beginner Guide!
Kubernetes Application Deployment with Helm - A beginner Guide!Kubernetes Application Deployment with Helm - A beginner Guide!
Kubernetes Application Deployment with Helm - A beginner Guide!
 
Docker and the Linux Kernel
Docker and the Linux KernelDocker and the Linux Kernel
Docker and the Linux Kernel
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
Docker Networking Deep Dive
Docker Networking Deep DiveDocker Networking Deep Dive
Docker Networking Deep Dive
 

Destacado (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 a Dockerfile

Lecture eight to be introduced in class.
Lecture eight to be introduced in class.Lecture eight to be introduced in class.
Lecture eight to be introduced in class.
nigamsajal14
 

Similar a Dockerfile (20)

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)
 
Lecture eight to be introduced in class.
Lecture eight to be introduced in class.Lecture eight to be introduced in class.
Lecture eight to be introduced in class.
 
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
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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/