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

PPTX
Primi passi con Docker - ItalianCoders - 12-01-2021
PDF
Introduction to Docker - Learning containerization XP conference 2016
PDF
PDF
Introduction of Docker and Docker Compose
PPTX
Docker Starter Pack
PPTX
PPTX
Powercoders · Docker · Fall 2021.pptx
PPTX
Primi passi con Docker - ItalianCoders - 12-01-2021
Introduction to Docker - Learning containerization XP conference 2016
Introduction of Docker and Docker Compose
Docker Starter Pack
Powercoders · Docker · Fall 2021.pptx

Similar to Docker.pdf (20)

PPSX
Docker and containers - Presentation Slides by Priyadarshini Anand
PDF
Docker 101
PDF
Docker 101 - Intro to Docker
PPTX
Docker Workshop
PDF
Docker introduction - Part 1
PDF
Learning Docker with Thomas
PDF
Docker by Example - Basics
PDF
Introduction to Docker
PDF
docker.pdf
PDF
PDF
Computer science docker file Week -6 to7
PDF
Docker, but what it is?
PPTX
Introduction To Docker
PDF
Docker how to
PDF
Docker Introduction.pdf
PPTX
Docker for developers z java
PDF
Talk about Docker
PDF
Docker use dockerfile
PDF
Docker in a JS Developer’s Life
PDF
Getting Started with Docker (For Developers)
Docker and containers - Presentation Slides by Priyadarshini Anand
Docker 101
Docker 101 - Intro to Docker
Docker Workshop
Docker introduction - Part 1
Learning Docker with Thomas
Docker by Example - Basics
Introduction to Docker
docker.pdf
Computer science docker file Week -6 to7
Docker, but what it is?
Introduction To Docker
Docker how to
Docker Introduction.pdf
Docker for developers z java
Talk about Docker
Docker use dockerfile
Docker in a JS Developer’s Life
Getting Started with Docker (For Developers)
Ad

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Pre independence Education in Inndia.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Institutional Correction lecture only . . .
PDF
Classroom Observation Tools for Teachers
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
RMMM.pdf make it easy to upload and study
102 student loan defaulters named and shamed – Is someone you know on the list?
Anesthesia in Laparoscopic Surgery in India
2.FourierTransform-ShortQuestionswithAnswers.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O5-L3 Freight Transport Ops (International) V1.pdf
TR - Agricultural Crops Production NC III.pdf
Final Presentation General Medicine 03-08-2024.pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Pre independence Education in Inndia.pdf
Pharma ospi slides which help in ospi learning
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Cell Types and Its function , kingdom of life
O7-L3 Supply Chain Operations - ICLT Program
Institutional Correction lecture only . . .
Classroom Observation Tools for Teachers
Week 4 Term 3 Study Techniques revisited.pptx
RMMM.pdf make it easy to upload and study
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!