SlideShare a Scribd company logo
Docker
Waheed Iqbal
Infrastructure Management for Scalable Applications (Fall 2022)
Department of Data Science, FCIT, University of the Punjab
Lahore, Pakistan
Install Docker Engine on Ubuntu
● You need 64-bit version of one of these Ubuntu versions:
○ Ubuntu Kinetic 22.10
○ Ubuntu Jammy 22.04 (LTS)
○ Ubuntu Focal 20.04 (LTS)
○ Ubuntu Bionic 18.04 (LTS)
● Check your Ubuntu Release and Code Name using:
○ cat /etc/*release*
● Install using the convenience script (Click the link)
● The following two commands will install the docker on your Ubuntu machine
curl -fsSL https://get.docker.com -o get-docker.sh
DRY_RUN=1 sudo sh ./get-docker.sh
Install Docker Engine on Ubuntu (Cont.)
● If the installation works well, you see the following output:
Docker Commands
● docker run is a command used in the Docker command-line interface (CLI) to
run a command in a new container.
● OPTIONS are various options that can be passed to the command, such as specifying ports to
publish, setting environment variables, and mounting volumes.
● IMAGE is the image you want to use to create the container.
● COMMAND is the command you want to run inside the container.
● ARG are any arguments to be passed to the command.
Docker Commands (Cont.)
● docker ps is a command used in the Docker command-line interface (CLI) to
list all running containers on a system.
● The docker ps -a command lists all containers, both running and stopped, on
a system.
● Docker stop [NAME/ID of Container] stops the running container
Docker Commands (Cont.)
● Docker start [NAME/ID of Container] starts the stopped container. It will
restore the file system for the container too.
● docker rm is a command used in the Docker command-line interface (CLI) to
remove one or more containers.
Docker Commands (Cont.)
Docker Commands (Cont.)
● docker images will list local images, their repository, tags, and their size.
● docker rmi removes images from the host node.
Docker Commands (Cont.)
● docker run downloads image
from docker registry locally
and then run it.
● docker pull only downloads
image from docker registry
locally.
Docker Commands (Cont.)
● -i option stands for interactive, this allows you to interact with
the container
● -t option allows you to have a pseudo-terminal
● container_name is the name or ID of the container to connect to
● command is the command you want to run inside the container
● docker exec is a command used to run a command inside an existing running container.
Docker Commands (Cont.)
What happened here?
Docker Commands (Cont.)
● Docker by default run some command inside. If there is no command defined the
container terminates right after running
● For example docker run ubuntu will run ubuntu container but terminate as we do not
define any command and there is no default command for this image
Docker Commands (Cont.)
The docker inspect command is used to get detailed information about Docker objects such as
images, containers, networks, and volumes. By default it returns data in the form of a JSON array.
Docker Commands (Cont.)
The docker logs command
shows information logged by a
running container.
Docker Commands (Cont.)
Tags
● Docker Images are
managed by tags.
● The default tag for every
image is latest. However,
we can also use specific
tags.
● Tags are mostly used to
refer a specific version.
Docker Hub
Volume Mapping
Once we remove/delete docker, the file system of the docker also destroyed. We
can map a local directory to the container for avoid it.
● docker run –v /opt/datadir:/var/lib/mysql mysql
○ /opt/datadir is local directory in the host node
○ /var/lib/mysql is directory in the container
Assignment 01: Getting Comfortable With Dockers
1. Install docker engine on your machine
2. Run jenkins container on your machine
3. Access it through internal IP on the default port
4. Re-run the container with port mapping and access it through external IP and
a custom port
5. Make a loom video to show me docker commands and the web interfaces
accessed via your browser
I will send more details about the submission on Google Classroom!
Docker Environment Variable
Docker Environment Variable (Cont.)
Docker Environment Variable (Cont.)
Docker Environment Variable (Cont.)
Building Custom Docker Images
● A Dockerfile is a script that contains instructions for building a Docker image.
● It is used to automate the process of creating a container image.
● It typically includes information about the base image, any additional software
that needs to be installed, and any configurations or environment variables that
need to be set.
● The basic syntax for Dockerfile is:
INSTRUCTION arguments
Dockerfile
The most commonly used instructions in Dockerfile are:
● FROM: specifies the base image for the build
● RUN: runs a command to install software or make other changes to the image
● COPY: copies files or directories from the host machine to the image
● ENV: sets environment variables
● EXPOSE: specifies the ports that the container will listen on
● CMD: specifies the command that will be run when a container is started from the image
● ENTRYPOINT: instruction sets the command that will be executed when the container is started from the image.
Unlike the CMD instruction, the ENTRYPOINT instruction does not get overridden when additional command-line arguments
are passed to the docker run command
Dockerfile (Cont.)
Dockerfile (Cont.)
Docker Compose
● Docker Compose is a tool for defining and running multi-container Docker applications.
● It is used to define the services, networks and volumes for the application, and then starts and stops
all of the containers with a single command.
● The configuration for the application is defined in a docker-compose.yml file, which specifies the
services, their dependencies, and their configuration.
● This allows developers to easily manage and scale their applications, and makes it easy to run the
application in different environments.
● It also provides a way to run multiple container applications together, by grouping all the services in
one compose file.
Docker Compose (Cont.)
Docker Compose (Cont.)
Docker Compose (Cont.)
Docker Compose (Cont.)
● The --link option in docker run
allows you to link one container to
another. Syntax:
docker run --link <name/id of container to link>:<alias
in the running container> <image name>
● --link redis:redis in the example is
linking voting-app with redis
container whereas redis is also
used alias in voting-app to access
the redis container.
Docker Compose (Cont.)
Docker Compose (Cont.)
● First time, you need to install docker-compose. You can do using the following two commands:
○ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o
/usr/local/bin/docker-compose
○ sudo chmod +x /usr/local/bin/docker-compose
Docker Compose (Cont.)
If the image is not in
the registry. We can
instruct docker
compose to build the
image from a local
folder which contain
source code of the
app and Dockerfile
Docker Compose (Cont.)
The latest is version 3.
All the features of version
2 are available in it. We
do not need to specify
links and it can support
multiple networks. We
mostly use version 2.
Docker Compose (Cont.)
Assignment 02: Load Balance an Application
● Use Nginx as loadbalancer
● Use any web application, prepare its docker image
● Use docker compose to automate the process for launching the application
with 2 replicas behind the loadbalancer
● Show the requests serving through different replica through Nginx
Credit
Part of slides are taken from KodeKloud!

More Related Content

Similar to Docker.pdf (20)

PPTX
Primi passi con Docker - ItalianCoders - 12-01-2021
Alessandro Mignogna
 
PDF
DOCKER-PIAIC-SLIDES
MuhammadAhmed651877
 
PPTX
Docker, LinuX Container
Araf Karsh Hamid
 
PDF
Docker Up and Running for Web Developers
Amr Fawzy
 
PDF
Docker up and Running For Web Developers
BADR
 
PDF
Docker Introduction
MANAOUIL Karim
 
PPTX
Docker
Hussien Elhannan
 
PPTX
Academy PRO: Docker. Lecture 2
Binary Studio
 
PDF
Docker introduction - Part 1
Alessandro Mignogna
 
PDF
Introduction of Docker and Docker Compose
Dr. Ketan Parmar
 
PDF
Introduction to Docker - Learning containerization XP conference 2016
XP Conference India
 
PPTX
Introduction To Docker
Dr. Syed Hassan Amin
 
PPTX
Getting Started With Docker: Simplifying DevOps
demoNguyen
 
PDF
From zero to Docker
Giovanni Toraldo
 
PPSX
Docker and containers - Presentation Slides by Priyadarshini Anand
PRIYADARSHINI ANAND
 
PDF
Docker 101
Mirza Nafis Faysal
 
PDF
How to write a Dockerfile
Knoldus Inc.
 
PDF
[@NaukriEngineering] Docker 101
Naukri.com
 
PPTX
Docker
Dmitry Bolgarov
 
PPTX
Docker Command Line, Using and Choosing containers
Will Hall
 
Primi passi con Docker - ItalianCoders - 12-01-2021
Alessandro Mignogna
 
DOCKER-PIAIC-SLIDES
MuhammadAhmed651877
 
Docker, LinuX Container
Araf Karsh Hamid
 
Docker Up and Running for Web Developers
Amr Fawzy
 
Docker up and Running For Web Developers
BADR
 
Docker Introduction
MANAOUIL Karim
 
Academy PRO: Docker. Lecture 2
Binary Studio
 
Docker introduction - Part 1
Alessandro Mignogna
 
Introduction of Docker and Docker Compose
Dr. Ketan Parmar
 
Introduction to Docker - Learning containerization XP conference 2016
XP Conference India
 
Introduction To Docker
Dr. Syed Hassan Amin
 
Getting Started With Docker: Simplifying DevOps
demoNguyen
 
From zero to Docker
Giovanni Toraldo
 
Docker and containers - Presentation Slides by Priyadarshini Anand
PRIYADARSHINI ANAND
 
Docker 101
Mirza Nafis Faysal
 
How to write a Dockerfile
Knoldus Inc.
 
[@NaukriEngineering] Docker 101
Naukri.com
 
Docker Command Line, Using and Choosing containers
Will Hall
 

Recently uploaded (20)

PPTX
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Ad

Docker.pdf

  • 1. Docker Waheed Iqbal Infrastructure Management for Scalable Applications (Fall 2022) Department of Data Science, FCIT, University of the Punjab Lahore, Pakistan
  • 2. Install Docker Engine on Ubuntu ● You need 64-bit version of one of these Ubuntu versions: ○ Ubuntu Kinetic 22.10 ○ Ubuntu Jammy 22.04 (LTS) ○ Ubuntu Focal 20.04 (LTS) ○ Ubuntu Bionic 18.04 (LTS) ● Check your Ubuntu Release and Code Name using: ○ cat /etc/*release* ● Install using the convenience script (Click the link) ● The following two commands will install the docker on your Ubuntu machine curl -fsSL https://get.docker.com -o get-docker.sh DRY_RUN=1 sudo sh ./get-docker.sh
  • 3. Install Docker Engine on Ubuntu (Cont.) ● If the installation works well, you see the following output:
  • 4. Docker Commands ● docker run is a command used in the Docker command-line interface (CLI) to run a command in a new container. ● OPTIONS are various options that can be passed to the command, such as specifying ports to publish, setting environment variables, and mounting volumes. ● IMAGE is the image you want to use to create the container. ● COMMAND is the command you want to run inside the container. ● ARG are any arguments to be passed to the command.
  • 5. Docker Commands (Cont.) ● docker ps is a command used in the Docker command-line interface (CLI) to list all running containers on a system. ● The docker ps -a command lists all containers, both running and stopped, on a system. ● Docker stop [NAME/ID of Container] stops the running container
  • 6. Docker Commands (Cont.) ● Docker start [NAME/ID of Container] starts the stopped container. It will restore the file system for the container too. ● docker rm is a command used in the Docker command-line interface (CLI) to remove one or more containers.
  • 8. Docker Commands (Cont.) ● docker images will list local images, their repository, tags, and their size. ● docker rmi removes images from the host node.
  • 9. Docker Commands (Cont.) ● docker run downloads image from docker registry locally and then run it. ● docker pull only downloads image from docker registry locally.
  • 10. Docker Commands (Cont.) ● -i option stands for interactive, this allows you to interact with the container ● -t option allows you to have a pseudo-terminal ● container_name is the name or ID of the container to connect to ● command is the command you want to run inside the container ● docker exec is a command used to run a command inside an existing running container.
  • 12. Docker Commands (Cont.) ● Docker by default run some command inside. If there is no command defined the container terminates right after running ● For example docker run ubuntu will run ubuntu container but terminate as we do not define any command and there is no default command for this image
  • 13. Docker Commands (Cont.) The docker inspect command is used to get detailed information about Docker objects such as images, containers, networks, and volumes. By default it returns data in the form of a JSON array.
  • 14. Docker Commands (Cont.) The docker logs command shows information logged by a running container.
  • 16. Tags ● Docker Images are managed by tags. ● The default tag for every image is latest. However, we can also use specific tags. ● Tags are mostly used to refer a specific version.
  • 18. Volume Mapping Once we remove/delete docker, the file system of the docker also destroyed. We can map a local directory to the container for avoid it. ● docker run –v /opt/datadir:/var/lib/mysql mysql ○ /opt/datadir is local directory in the host node ○ /var/lib/mysql is directory in the container
  • 19. Assignment 01: Getting Comfortable With Dockers 1. Install docker engine on your machine 2. Run jenkins container on your machine 3. Access it through internal IP on the default port 4. Re-run the container with port mapping and access it through external IP and a custom port 5. Make a loom video to show me docker commands and the web interfaces accessed via your browser I will send more details about the submission on Google Classroom!
  • 24. Building Custom Docker Images ● A Dockerfile is a script that contains instructions for building a Docker image. ● It is used to automate the process of creating a container image. ● It typically includes information about the base image, any additional software that needs to be installed, and any configurations or environment variables that need to be set. ● The basic syntax for Dockerfile is: INSTRUCTION arguments
  • 25. Dockerfile The most commonly used instructions in Dockerfile are: ● FROM: specifies the base image for the build ● RUN: runs a command to install software or make other changes to the image ● COPY: copies files or directories from the host machine to the image ● ENV: sets environment variables ● EXPOSE: specifies the ports that the container will listen on ● CMD: specifies the command that will be run when a container is started from the image ● ENTRYPOINT: instruction sets the command that will be executed when the container is started from the image. Unlike the CMD instruction, the ENTRYPOINT instruction does not get overridden when additional command-line arguments are passed to the docker run command
  • 28. Docker Compose ● Docker Compose is a tool for defining and running multi-container Docker applications. ● It is used to define the services, networks and volumes for the application, and then starts and stops all of the containers with a single command. ● The configuration for the application is defined in a docker-compose.yml file, which specifies the services, their dependencies, and their configuration. ● This allows developers to easily manage and scale their applications, and makes it easy to run the application in different environments. ● It also provides a way to run multiple container applications together, by grouping all the services in one compose file.
  • 32. Docker Compose (Cont.) ● The --link option in docker run allows you to link one container to another. Syntax: docker run --link <name/id of container to link>:<alias in the running container> <image name> ● --link redis:redis in the example is linking voting-app with redis container whereas redis is also used alias in voting-app to access the redis container.
  • 34. Docker Compose (Cont.) ● First time, you need to install docker-compose. You can do using the following two commands: ○ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose ○ sudo chmod +x /usr/local/bin/docker-compose
  • 35. Docker Compose (Cont.) If the image is not in the registry. We can instruct docker compose to build the image from a local folder which contain source code of the app and Dockerfile
  • 36. Docker Compose (Cont.) The latest is version 3. All the features of version 2 are available in it. We do not need to specify links and it can support multiple networks. We mostly use version 2.
  • 38. Assignment 02: Load Balance an Application ● Use Nginx as loadbalancer ● Use any web application, prepare its docker image ● Use docker compose to automate the process for launching the application with 2 replicas behind the loadbalancer ● Show the requests serving through different replica through Nginx
  • 39. Credit Part of slides are taken from KodeKloud!