SlideShare a Scribd company logo
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
Agenda
What is DevOps?
DevOps Use Case
DevOps Phases
DevOps Hands-On
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
Topics for Today’s Session
www.edureka.co/devopsDevOps Certification Training
What is Docker?1
What is a Dockerfile?2
Dockerfile syntax3
Hands-on: Dockerizing Apache & Nginx4
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
What is Docker?
www.edureka.co/devopsDevOps Certification Training
The Old Way: Application on Host The New Way: Deploy Containers
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
How To Use Docker?
www.edureka.co/devopsDevOps Certification Training
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
How to build
Docker Images?
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
How To Build Docker Images? – Using Predefined Images
www.edureka.co/devopsDevOps Certification Training
Pull Docker Images
Run Docker Images
to Create Docker
Containers
Docker
Container
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
What if I want to
create my own
image?
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
How To Build Docker Images? – Using DockerFile
www.edureka.co/devopsDevOps Certification Training
DockerFile
Dockerfile is a script, composed of various commands (instructions) and arguments listed successively to automatically perform actions on a
base image in order to create (or form) a new one
Base Image
RUN
FROM
MAINTAINER
ADD
CMD
ENTRYPOINT
ENV
EXPOSE
USER
VOLUME
WORKDIR
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
How To Write A
DockerFile?
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Syntax
www.edureka.co/devopsDevOps Certification Training
Dockerfile syntax consists of two kind of main line blocks: comments and commands + arguments
# Line blocks used for commenting
command argument argument1...
Syntax
# Print “Welcome To Edureka!”
RUN echo “Welcome To Edureka!”
Example
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
Let’s have a look at Different Set of Commands which DockerFile can
Contain Before working on a DockerFile Example
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – FROM
www.edureka.co/devopsDevOps Certification Training
FROM
FROM directive is probably the most crucial amongst all others for Dockerfiles. It defines the base image to
use to start the build process
# Usage: FROM [image name]
FROM ubuntu
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – RUN
www.edureka.co/devopsDevOps Certification Training
RUN
The RUN command is the central executing directive for Dockerfiles. It takes a command as its argument
and runs it to form the image. Unlike CMD, it actually is used to build the image
# Usage: RUN [command]
RUN apt-get install -y riak
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – CMD
www.edureka.co/devopsDevOps Certification Training
CMD
The command CMD, similar to RUN, can be used for executing a specific command. However, unlike RUN it
is not executed during build, but when a container is instantiated using the image being built
# Usage 1: CMD application "argument", "argument", ..
CMD "echo" " Welcome To Edureka!"
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – ENTRYPOINT
www.edureka.co/devopsDevOps Certification Training
ENTRYPOINT
ENTRYPOINT argument sets the concrete default application that is used every time a container is created
using the image
# Usage: ENTRYPOINT application "argument", "argument", ..
# Remember: arguments are optional. They can be provided by CMD
# or during the creation of a container.
ENTRYPOINT echo
# Usage example with CMD:
# Arguments set with CMD can be overridden during *run* CMD "Hello docker!"
CMD “Welcome to edureka!”
ENTRYPOINT echo
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – ADD
www.edureka.co/devopsDevOps Certification Training
ADD
The ADD command gets two arguments: a source and a destination. It basically copies the files from
the source on the host into the container's own filesystem at the set destination
# Usage: ADD [source directory or URL] [destination directory]
ADD /my_app_folder /my_app_folder
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – ENV
www.edureka.co/devopsDevOps Certification Training
ENV
The ENV command is used to set the environment variables (one or more). These variables consist of “key
value” pairs which can be accessed within the container by scripts and applications alike
# Usage: ENV key value
ENV SERVER_WORKS 4
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – WORKDIR
www.edureka.co/devopsDevOps Certification Training
WORKDIR The WORKDIR directive is used to set where the command defined with CMD is to be executed
# Usage:
WORKDIR /path WORKDIR ~/
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – EXPOSE
www.edureka.co/devopsDevOps Certification Training
EXPOSE
The EXPOSE command is used to associate a specified port to enable networking between the running
process inside the container and the outside world (i.e. the host)
# Usage: EXPOSE [port]
EXPOSE 8080
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – MAINTAINER
www.edureka.co/devopsDevOps Certification Training
MAINTAINER
This non-executing command declares the author, hence setting the author field of the images. It should
come nonetheless after FROM
# Usage: MAINTAINER [name]
MAINTAINER authors_name
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – USER
www.edureka.co/devopsDevOps Certification Training
USER
The USER directive is used to set the UID (or username) which is to run the container based on the image
being built
# Usage: USER [UID]
USER 751
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
DockerFile Commands – VOLUME
www.edureka.co/devopsDevOps Certification Training
VOLUME
The VOLUME command is used to enable access from your container to a directory on the host machine
(i.e. mounting it)
# Usage: VOLUME ["/dir_1", "/dir_2" ..]
VOLUME ["/my_files"]
Example:
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
Creating an Image to Install Apache Web Server
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
FROM ubuntu:12.04
MAINTAINER edureka
RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
DockerFile For Installing Apache
www.edureka.co/devopsDevOps Certification Training
In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a
reverse proxy and load balancer for HTTP, TCP, and UDP servers.
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile For Installing Nginx
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
DockerFile Tutorial
www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING
FROM ubuntu:14.04
MAINTAINER edureka
RUN apt-get update
RUN apt-get install -y nginx
ADD index.html /usr/share/nginx/html/index.html
ENTRYPOINT ["/usr/sbin/nginx", "-g", "daemon off;"]
EXPOSE 80
DockerFile For Installing Nginx
www.edureka.co/devopsDevOps Certification Training
Apache2 Web Server. Apache is the most commonly used Web server on Linux systems. Web servers are used to serve Web
pages requested by client computers
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Training | Edureka

More Related Content

PDF
Introduction to docker
Instruqt
 
PDF
Docker Introduction
Peng Xiao
 
PDF
Ansible - Hands on Training
Mehmet Ali Aydın
 
PPTX
Introduction to docker
Frederik Mogensen
 
PPTX
Virtual machines and containers
Patrick Pierson
 
PPTX
What is Docker
Pavel Klimiankou
 
PPTX
Docker introduction for the beginners
Juneyoung Oh
 
PDF
Introduction to Docker storage, volume and image
ejlp12
 
Introduction to docker
Instruqt
 
Docker Introduction
Peng Xiao
 
Ansible - Hands on Training
Mehmet Ali Aydın
 
Introduction to docker
Frederik Mogensen
 
Virtual machines and containers
Patrick Pierson
 
What is Docker
Pavel Klimiankou
 
Docker introduction for the beginners
Juneyoung Oh
 
Introduction to Docker storage, volume and image
ejlp12
 

What's hot (20)

PDF
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
Edureka!
 
PDF
왕초보를 위한 도커 사용법
GeunCheolYeom
 
PDF
Docker by Example - Basics
CodeOps Technologies LLP
 
PDF
From Zero to Docker
Abhishek Verma
 
PPTX
Introduction to react_js
MicroPyramid .
 
PPTX
Dockers and containers basics
Sourabh Saxena
 
PPT
Docker introduction
Phuc Nguyen
 
PPTX
React-JS.pptx
AnmolPandita7
 
PDF
Dockerfile
Jeffrey Ellin
 
PPTX
Docker introduction & benefits
Amit Manwade
 
PDF
Introduction to Docker Compose
Ajeet Singh Raina
 
PDF
Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...
Edureka!
 
PDF
Introduction to Docker - VIT Campus
Ajeet Singh Raina
 
PPTX
Docker Basics
DuckDuckGo
 
PDF
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
Arawn Park
 
PPTX
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
Simplilearn
 
PDF
Spring Boot
koppenolski
 
PPSX
Containers Docker Kind Kubernetes Istio
Araf Karsh Hamid
 
PPTX
Maven ppt
natashasweety7
 
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
Edureka!
 
왕초보를 위한 도커 사용법
GeunCheolYeom
 
Docker by Example - Basics
CodeOps Technologies LLP
 
From Zero to Docker
Abhishek Verma
 
Introduction to react_js
MicroPyramid .
 
Dockers and containers basics
Sourabh Saxena
 
Docker introduction
Phuc Nguyen
 
React-JS.pptx
AnmolPandita7
 
Dockerfile
Jeffrey Ellin
 
Docker introduction & benefits
Amit Manwade
 
Introduction to Docker Compose
Ajeet Singh Raina
 
Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...
Edureka!
 
Introduction to Docker - VIT Campus
Ajeet Singh Raina
 
Docker Basics
DuckDuckGo
 
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
Arawn Park
 
Docker Compose | Docker Compose Tutorial | Docker Tutorial For Beginners | De...
Simplilearn
 
Spring Boot
koppenolski
 
Containers Docker Kind Kubernetes Istio
Araf Karsh Hamid
 
Maven ppt
natashasweety7
 
Ad

Similar to Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Training | Edureka (20)

PPTX
Docker team training
Karthik Venkateswaran
 
PDF
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Edureka!
 
PDF
Docker For Windows | Setting Up Docker On Windows | Edureka
Edureka!
 
PDF
Introduction to DevOps | Edureka
Edureka!
 
PDF
Docker Introduction.pdf
OKLABS
 
PDF
Docker Commands With Examples | Docker Tutorial | DevOps Tutorial | Docker Tr...
Edureka!
 
PDF
Docker @ Atlogys
Atlogys Technical Consulting
 
PDF
dockerizing web application
Walid Ashraf
 
PDF
DevOps-Redefining your IT Strategy-28thJan15
Edureka!
 
PDF
Linux Training For Beginners | Linux Administration Tutorial | Introduction T...
Edureka!
 
PDF
Docker Networking | Container Network Model (CNM) | Docker Tutorial For Begin...
Edureka!
 
PDF
Docker Compose | Containerizing MEAN Stack Application | DevOps Tutorial | Ed...
Edureka!
 
PDF
Continuous Delivery with Docker and Jenkins pipeline
Slam Han
 
PDF
Docker how to
Patryk Omiotek
 
PDF
Of Docker and Drupal
Gerald Villorente
 
PDF
Docker vs VM | | Containerization or Virtualization - The Differences | DevOp...
Edureka!
 
PDF
Docker for developers on mac and windows
Docker, Inc.
 
PPTX
[Codelab 2017] Docker 기초 및 활용 방안
양재동 코드랩
 
PPTX
Docker @ FOSS4G 2016, Bonn
Daniel Nüst
 
PPTX
Screw DevOps, Let's Talk DataOps
Kellyn Pot'Vin-Gorman
 
Docker team training
Karthik Venkateswaran
 
Docker Swarm For High Availability | Docker Tutorial | DevOps Tutorial | Edureka
Edureka!
 
Docker For Windows | Setting Up Docker On Windows | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Edureka!
 
Docker Introduction.pdf
OKLABS
 
Docker Commands With Examples | Docker Tutorial | DevOps Tutorial | Docker Tr...
Edureka!
 
dockerizing web application
Walid Ashraf
 
DevOps-Redefining your IT Strategy-28thJan15
Edureka!
 
Linux Training For Beginners | Linux Administration Tutorial | Introduction T...
Edureka!
 
Docker Networking | Container Network Model (CNM) | Docker Tutorial For Begin...
Edureka!
 
Docker Compose | Containerizing MEAN Stack Application | DevOps Tutorial | Ed...
Edureka!
 
Continuous Delivery with Docker and Jenkins pipeline
Slam Han
 
Docker how to
Patryk Omiotek
 
Of Docker and Drupal
Gerald Villorente
 
Docker vs VM | | Containerization or Virtualization - The Differences | DevOp...
Edureka!
 
Docker for developers on mac and windows
Docker, Inc.
 
[Codelab 2017] Docker 기초 및 활용 방안
양재동 코드랩
 
Docker @ FOSS4G 2016, Bonn
Daniel Nüst
 
Screw DevOps, Let's Talk DataOps
Kellyn Pot'Vin-Gorman
 
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
PDF
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
PDF
Tableau Tutorial for Data Science | Edureka
Edureka!
 
PDF
Python Programming Tutorial | Edureka
Edureka!
 
PDF
Top 5 PMP Certifications | Edureka
Edureka!
 
PDF
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
PDF
Linux Mint Tutorial | Edureka
Edureka!
 
PDF
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
PDF
Importance of Digital Marketing | Edureka
Edureka!
 
PDF
RPA in 2020 | Edureka
Edureka!
 
PDF
Email Notifications in Jenkins | Edureka
Edureka!
 
PDF
EA Algorithm in Machine Learning | Edureka
Edureka!
 
PDF
Cognitive AI Tutorial | Edureka
Edureka!
 
PDF
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
PDF
Blue Prism Top Interview Questions | Edureka
Edureka!
 
PDF
Big Data on AWS Tutorial | Edureka
Edureka!
 
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
PDF
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
PDF
ITIL® Tutorial for Beginners | ITIL® Foundation Training | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
ITIL® Tutorial for Beginners | ITIL® Foundation Training | Edureka
Edureka!
 

Recently uploaded (20)

PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PPT
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
This slide provides an overview Technology
mineshkharadi333
 
L2 Rules of Netiquette in Empowerment technology
Archibal2
 

Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Training | Edureka

  • 1. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING Agenda What is DevOps? DevOps Use Case DevOps Phases DevOps Hands-On
  • 2. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING Topics for Today’s Session www.edureka.co/devopsDevOps Certification Training What is Docker?1 What is a Dockerfile?2 Dockerfile syntax3 Hands-on: Dockerizing Apache & Nginx4
  • 3. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING What is Docker? www.edureka.co/devopsDevOps Certification Training The Old Way: Application on Host The New Way: Deploy Containers
  • 4. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING How To Use Docker? www.edureka.co/devopsDevOps Certification Training
  • 5. Copyright © 2017, edureka and/or its affiliates. All rights reserved. How to build Docker Images?
  • 6. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING How To Build Docker Images? – Using Predefined Images www.edureka.co/devopsDevOps Certification Training Pull Docker Images Run Docker Images to Create Docker Containers Docker Container
  • 7. Copyright © 2017, edureka and/or its affiliates. All rights reserved. What if I want to create my own image?
  • 8. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING How To Build Docker Images? – Using DockerFile www.edureka.co/devopsDevOps Certification Training DockerFile Dockerfile is a script, composed of various commands (instructions) and arguments listed successively to automatically perform actions on a base image in order to create (or form) a new one Base Image RUN FROM MAINTAINER ADD CMD ENTRYPOINT ENV EXPOSE USER VOLUME WORKDIR
  • 9. Copyright © 2017, edureka and/or its affiliates. All rights reserved. How To Write A DockerFile?
  • 10. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Syntax www.edureka.co/devopsDevOps Certification Training Dockerfile syntax consists of two kind of main line blocks: comments and commands + arguments # Line blocks used for commenting command argument argument1... Syntax # Print “Welcome To Edureka!” RUN echo “Welcome To Edureka!” Example
  • 11. Copyright © 2017, edureka and/or its affiliates. All rights reserved. Let’s have a look at Different Set of Commands which DockerFile can Contain Before working on a DockerFile Example
  • 12. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – FROM www.edureka.co/devopsDevOps Certification Training FROM FROM directive is probably the most crucial amongst all others for Dockerfiles. It defines the base image to use to start the build process # Usage: FROM [image name] FROM ubuntu Example:
  • 13. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – RUN www.edureka.co/devopsDevOps Certification Training RUN The RUN command is the central executing directive for Dockerfiles. It takes a command as its argument and runs it to form the image. Unlike CMD, it actually is used to build the image # Usage: RUN [command] RUN apt-get install -y riak Example:
  • 14. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – CMD www.edureka.co/devopsDevOps Certification Training CMD The command CMD, similar to RUN, can be used for executing a specific command. However, unlike RUN it is not executed during build, but when a container is instantiated using the image being built # Usage 1: CMD application "argument", "argument", .. CMD "echo" " Welcome To Edureka!" Example:
  • 15. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – ENTRYPOINT www.edureka.co/devopsDevOps Certification Training ENTRYPOINT ENTRYPOINT argument sets the concrete default application that is used every time a container is created using the image # Usage: ENTRYPOINT application "argument", "argument", .. # Remember: arguments are optional. They can be provided by CMD # or during the creation of a container. ENTRYPOINT echo # Usage example with CMD: # Arguments set with CMD can be overridden during *run* CMD "Hello docker!" CMD “Welcome to edureka!” ENTRYPOINT echo Example:
  • 16. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – ADD www.edureka.co/devopsDevOps Certification Training ADD The ADD command gets two arguments: a source and a destination. It basically copies the files from the source on the host into the container's own filesystem at the set destination # Usage: ADD [source directory or URL] [destination directory] ADD /my_app_folder /my_app_folder Example:
  • 17. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – ENV www.edureka.co/devopsDevOps Certification Training ENV The ENV command is used to set the environment variables (one or more). These variables consist of “key value” pairs which can be accessed within the container by scripts and applications alike # Usage: ENV key value ENV SERVER_WORKS 4 Example:
  • 18. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – WORKDIR www.edureka.co/devopsDevOps Certification Training WORKDIR The WORKDIR directive is used to set where the command defined with CMD is to be executed # Usage: WORKDIR /path WORKDIR ~/ Example:
  • 19. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – EXPOSE www.edureka.co/devopsDevOps Certification Training EXPOSE The EXPOSE command is used to associate a specified port to enable networking between the running process inside the container and the outside world (i.e. the host) # Usage: EXPOSE [port] EXPOSE 8080 Example:
  • 20. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – MAINTAINER www.edureka.co/devopsDevOps Certification Training MAINTAINER This non-executing command declares the author, hence setting the author field of the images. It should come nonetheless after FROM # Usage: MAINTAINER [name] MAINTAINER authors_name Example:
  • 21. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – USER www.edureka.co/devopsDevOps Certification Training USER The USER directive is used to set the UID (or username) which is to run the container based on the image being built # Usage: USER [UID] USER 751 Example:
  • 22. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING DockerFile Commands – VOLUME www.edureka.co/devopsDevOps Certification Training VOLUME The VOLUME command is used to enable access from your container to a directory on the host machine (i.e. mounting it) # Usage: VOLUME ["/dir_1", "/dir_2" ..] VOLUME ["/my_files"] Example:
  • 23. Copyright © 2017, edureka and/or its affiliates. All rights reserved. Creating an Image to Install Apache Web Server
  • 24. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING FROM ubuntu:12.04 MAINTAINER edureka RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/* ENV APACHE_RUN_USER www-data ENV APACHE_RUN_GROUP www-data ENV APACHE_LOG_DIR /var/log/apache2 EXPOSE 80 CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"] DockerFile For Installing Apache www.edureka.co/devopsDevOps Certification Training In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.
  • 25. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile For Installing Nginx
  • 26. Copyright © 2017, edureka and/or its affiliates. All rights reserved. DockerFile Tutorial www.edureka.co/devopsDEVOPS CERTIFICATION TRAINING FROM ubuntu:14.04 MAINTAINER edureka RUN apt-get update RUN apt-get install -y nginx ADD index.html /usr/share/nginx/html/index.html ENTRYPOINT ["/usr/sbin/nginx", "-g", "daemon off;"] EXPOSE 80 DockerFile For Installing Nginx www.edureka.co/devopsDevOps Certification Training Apache2 Web Server. Apache is the most commonly used Web server on Linux systems. Web servers are used to serve Web pages requested by client computers
  • 27. Copyright © 2017, edureka and/or its affiliates. All rights reserved.