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

What's hot (20)

PDF
Docker Introduction
MANAOUIL Karim
 
PDF
What is Docker Architecture | Edureka
Edureka!
 
PDF
Docker in real life
Nguyen Van Vuong
 
PPTX
Docker introduction & benefits
Amit Manwade
 
PPTX
Docker introduction
dotCloud
 
PDF
Introduction to Docker
Aditya Konarde
 
PPTX
Kubernetes PPT.pptx
ssuser0cc9131
 
PPTX
Docker 101 : Introduction to Docker and Containers
Yajushi Srivastava
 
PDF
Docker Compose by Aanand Prasad
Docker, Inc.
 
PPTX
Terraform
Pathum Fernando ☁
 
PDF
Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...
Edureka!
 
PDF
Introduction to Tekton
Victor Iglesias
 
PPTX
Kubernetes 101
Stanislav Pogrebnyak
 
PPTX
Infrastructure-as-Code (IaC) using Terraform
Adin Ermie
 
PPTX
Deploying Azure DevOps using Terraform
Adin Ermie
 
PDF
Docker introduction
Julien Maitrehenry
 
PDF
What Is Helm
AMELIAOLIVIA2
 
PDF
How to write a Dockerfile
Knoldus Inc.
 
PDF
Docker Registry V2
Docker, Inc.
 
Docker Introduction
MANAOUIL Karim
 
What is Docker Architecture | Edureka
Edureka!
 
Docker in real life
Nguyen Van Vuong
 
Docker introduction & benefits
Amit Manwade
 
Docker introduction
dotCloud
 
Introduction to Docker
Aditya Konarde
 
Kubernetes PPT.pptx
ssuser0cc9131
 
Docker 101 : Introduction to Docker and Containers
Yajushi Srivastava
 
Docker Compose by Aanand Prasad
Docker, Inc.
 
Docker Explained | What Is A Docker Container? | Docker Simplified | Docker T...
Edureka!
 
Introduction to Tekton
Victor Iglesias
 
Kubernetes 101
Stanislav Pogrebnyak
 
Infrastructure-as-Code (IaC) using Terraform
Adin Ermie
 
Deploying Azure DevOps using Terraform
Adin Ermie
 
Docker introduction
Julien Maitrehenry
 
What Is Helm
AMELIAOLIVIA2
 
How to write a Dockerfile
Knoldus Inc.
 
Docker Registry V2
Docker, Inc.
 

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

PDF
Getting Started with Docker
Anup Segu
 
PPTX
Docker advance1
Gourav Varma
 
PPTX
Docker advance topic
Kalkey
 
PPTX
Primi passi con Docker - ItalianCoders - 12-01-2021
Alessandro Mignogna
 
PDF
Docker From Zero To Hero Your Devops Kickstart Build Deploy And Manage Contai...
sroshmoamin
 
PPTX
Building Images
Dawood M.S
 
PDF
Docker @ Atlogys
Atlogys Technical Consulting
 
PDF
Docker Commands With Examples | Docker Tutorial | DevOps Tutorial | Docker Tr...
Edureka!
 
PDF
Getting Started With Docker | Docker Tutorial | Docker Training | Edureka
Edureka!
 
PDF
[@NaukriEngineering] Docker 101
Naukri.com
 
PDF
Lecture eight to be introduced in class.
nigamsajal14
 
PDF
docker.pdf
EishaTirRaazia1
 
PPTX
Docker Workshop
Ahmad Rafiee
 
PDF
Getting Started with Docker (For Developers)
ColdFusionConference
 
PPTX
Docker Starter Pack
Saeed Hajizade
 
PDF
Computer science docker file Week -6 to7
jemy24r
 
PDF
Docker.pdf
UsamaMushtaq24
 
PPTX
Powercoders · Docker · Fall 2021.pptx
IgnacioTamayo2
 
PDF
Docker use dockerfile
cawamata
 
PDF
Docker in a JS Developer’s Life
GlobalLogic Ukraine
 
Getting Started with Docker
Anup Segu
 
Docker advance1
Gourav Varma
 
Docker advance topic
Kalkey
 
Primi passi con Docker - ItalianCoders - 12-01-2021
Alessandro Mignogna
 
Docker From Zero To Hero Your Devops Kickstart Build Deploy And Manage Contai...
sroshmoamin
 
Building Images
Dawood M.S
 
Docker Commands With Examples | Docker Tutorial | DevOps Tutorial | Docker Tr...
Edureka!
 
Getting Started With Docker | Docker Tutorial | Docker Training | Edureka
Edureka!
 
[@NaukriEngineering] Docker 101
Naukri.com
 
Lecture eight to be introduced in class.
nigamsajal14
 
docker.pdf
EishaTirRaazia1
 
Docker Workshop
Ahmad Rafiee
 
Getting Started with Docker (For Developers)
ColdFusionConference
 
Docker Starter Pack
Saeed Hajizade
 
Computer science docker file Week -6 to7
jemy24r
 
Docker.pdf
UsamaMushtaq24
 
Powercoders · Docker · Fall 2021.pptx
IgnacioTamayo2
 
Docker use dockerfile
cawamata
 
Docker in a JS Developer’s Life
GlobalLogic Ukraine
 
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
Introduction to DevOps | 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!
 
Introduction to DevOps | Edureka
Edureka!
 
Ad

Recently uploaded (20)

PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 

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.