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)

PPTX
Docker, LinuX Container
Araf Karsh Hamid
 
PPTX
Docker networking Tutorial 101
LorisPack Project
 
PDF
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Edureka!
 
PDF
Docker Compose by Aanand Prasad
Docker, Inc.
 
PDF
Introduction to Docker Compose
Ajeet Singh Raina
 
PDF
Kubernetes Application Deployment with Helm - A beginner Guide!
Krishna-Kumar
 
PDF
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
Ji-Woong Choi
 
PDF
Kubernetes Introduction
Peng Xiao
 
PDF
Docker Introduction
Peng Xiao
 
PPT
Ansible presentation
John Lynch
 
PPTX
Docker basics
AmanSoni129
 
PDF
Introduction to GitHub Actions
Knoldus Inc.
 
PDF
Jenkins Pipelines
Steffen Gebert
 
PDF
Ansible
Raul Leite
 
PPTX
Docker Tutorial For Beginners | What Is Docker And How It Works? | Docker Tut...
Simplilearn
 
PDF
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
OpenStack Korea Community
 
PPTX
Jenkins tutorial
Mamun Rashid, CCDH
 
PDF
CI/CD with Github Actions
Md. Minhazul Haque
 
PDF
Cloud-Native CI/CD on Kubernetes with Tekton Pipelines
Nikhil Thomas
 
Docker, LinuX Container
Araf Karsh Hamid
 
Docker networking Tutorial 101
LorisPack Project
 
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Edureka!
 
Docker Compose by Aanand Prasad
Docker, Inc.
 
Introduction to Docker Compose
Ajeet Singh Raina
 
Kubernetes Application Deployment with Helm - A beginner Guide!
Krishna-Kumar
 
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
Ji-Woong Choi
 
Kubernetes Introduction
Peng Xiao
 
Docker Introduction
Peng Xiao
 
Ansible presentation
John Lynch
 
Docker basics
AmanSoni129
 
Introduction to GitHub Actions
Knoldus Inc.
 
Jenkins Pipelines
Steffen Gebert
 
Ansible
Raul Leite
 
Docker Tutorial For Beginners | What Is Docker And How It Works? | Docker Tut...
Simplilearn
 
[OpenStack Days Korea 2016] Track1 - 카카오는 오픈스택 기반으로 어떻게 5000VM을 운영하고 있을까?
OpenStack Korea Community
 
Jenkins tutorial
Mamun Rashid, CCDH
 
CI/CD with Github Actions
Md. Minhazul Haque
 
Cloud-Native CI/CD on Kubernetes with Tekton Pipelines
Nikhil Thomas
 

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
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
Edureka!
 
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
 
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!
 
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
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
 
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!
 
Ad

Recently uploaded (20)

PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
Role_of_Artificial_Intelligence_in_Livestock_Extension_Services.pptx
DrRajdeepMadavi
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
NASA A Researcher’s Guide to International Space Station : Fundamental Physics
Dr. PANKAJ DHUSSA
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PPTX
Manual Testing for Accessibility Enhancement
Julia Undeutsch
 
PDF
Home Cleaning App Development Services.pdf
V3cube
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
Modern Decentralized Application Architectures.pdf
Kalema Edgar
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Evolution: How True AI is Redefining Safety in Industry 4.0
vikaassingh4433
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Role_of_Artificial_Intelligence_in_Livestock_Extension_Services.pptx
DrRajdeepMadavi
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
NASA A Researcher’s Guide to International Space Station : Fundamental Physics
Dr. PANKAJ DHUSSA
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
Manual Testing for Accessibility Enhancement
Julia Undeutsch
 
Home Cleaning App Development Services.pdf
V3cube
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Modern Decentralized Application Architectures.pdf
Kalema Edgar
 
Digital Circuits, important subject in CS
contactparinay1
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Evolution: How True AI is Redefining Safety in Industry 4.0
vikaassingh4433
 

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.