Docker
Image – running container
Container – fill some things (dep/repo/bin/lib)
Containerisation – use the filled things
Container advantages
Isolated – (EX: monomythic services (2017) = food delivery app [we have multiple option like
pages restaurant, order, payment] – the server build one big code – suppose we have trouble in
payment page means we stop the entire server and fix the issue)
 We use container means we install the server in multiple container and fix the all pages in
separate containers, suppose we facing issue in payment means stop the payment container
and fix the problem in this case we don’t need to stop entire server.
In one server – multiple container have means we install the same application in every
containers in same version.
This is called microservices.
Portable – we can use the container when we need and delete the container when no need the
service.
Container light weight, easy to use
Kernal sharing = container (ubuntu + kernal = ubuntu OS) – docker – ubuntu app and rhel app
All os have kernal, ubuntu is a just application, when adding the kernal means its called OS then
use container and run the different application.
The application want run any command means that time using the way of container the kernal
is working for the command running.
Kernal = GUI & CLI both methods can use
Roll update and roll back
Docker demon is working linux kernal to docker kernal command passing
Docker hub = we store the image
docker image
docker files = we create the image
we have 65500 port
we use the server in multiple container
multiple containers have same application
in this case we need to use port forwarding
EX: install the httpd in all container
Httpd port : 80
But container 1 running fb
Container 2 running insta
User access the container separately means use the port forwarding for two containers
Cont 1 : 8081, cont 2 : 8082
Day 2
Docker install
Docker image
Docker container
Update container
Convert from container to Image
Backup - > image
docker installing
# sudo apt update
# sudo apt install apt-transport-https ca-certificates curl software-properties-common
GPG key curl - download - license key- official website
docker repostory file add
policy - check
docker install # sudo apt install docker-ce
Image list = docker image ls
Container list running = docker ps
All container = docker ps -a
Command list = docker image –help
System commands
Df ,events
Info, prune
= docker pull httpd
= 65500 something port
= docker run -itd –name cont1 -p “8081:80” httpd (interact terminal Dameon)
Update =docker exec -it (container id) /bin/bash
= cd hddocs (user/local/apache2/hddocs)
= cat index.html
= apt install git -y
= apt install vim -y
Image convert = commit
container to image = Docker commit (container id) my image
image saving = docker save -o myimage.tar myimage
= docker stop
Only stopped container can remove = docker rm (container id
= docker rmi (image)
= docker load -I myimage.tar
= docker login -u (user name)
= password
= docker tag myimage userID/myimages1012
= docker push (tag name)
Practical
= sudo apt update
= sudo apt install apt-transport-https ca-certifications curl software-properties-common
License key (official website) = > curl -fsSL https://download.docker.com/linux/ubuntu/gpg |
sudo apt-key add -
Repository files = > sudo add-apt-repository "deb [arch=amd64]
https://download.docker.com/linux/ubuntu focal stable"
Check policy = > apt-cache policy docker-ce
Install docker = sudo apt install docker-ce
Image list view command = > docker image ls or docker images
Running Container command = > docker ps
All container list => docker ps -a
View all related command = docker image –help / docker container –help / docker system –help
Docker hub to server image pulling = docker pull httpd
Run the container = docker run -itd –name cont1 -p “8081:80” httpd
Itd means interact, terminal, demon (background working in every container)
Container name not must
Requirement for install git and vim
Enter container = docker exec -it (cont ID) /bin/bash
= cd htdocs
Container apache path = /usr/local/apache2/htdocs
Check working or not = cat index.html
= apt update
= apt install git -y
= apt install vim -y
Out of the container = exit
Container convert image (own image) = commit (need container id)
= docker ps
= docker commit (cont ID) myimage == > (name given by our self)
List the image and check
Image backup using the command “save”
= pwd
= ls
Backup = docker save -o myimage.tar myimage
Only stoped containers have removable
stop container = docker stop (cont ID)
remove container = docker rm (cont ID)
remove image = docker rmi (image name or ID)
image loading= docker load -i myimage.tar
connection docker hub = docker login -u (username)
=> password
Create tag and push
= docker tag myimage (username)/myimages1012
Which image – username – which name you push the image in docker hub
= docker push (username)/myimages1012
Day 3
Docker file
Sync
Link
Docker network
Docker compose
Build our own image using dockerfile
= vi Dockerfile
Script
FROM ubuntu:20.04
MAINTAINER Santhiya
LABEL (name,email, where im following)
RUN apt update -y
RUN apt install -y apache2
Building image = docker build -t newimage:v1 . (current file means give . / previous means we
mention path)
Suppose building own image in that time receiving error means we use this
[[[[[ ENV TZ=Asia/Dubai
RUN In -snf /usr/share/zoneinfo/$TZ/etc/localtime && echo STZ > /etc/timezone ]]]]]
docker file sample - search net
synk # docker run -itd --name apache12 -v "/opt/myapp:/usr/local/apache2/htdocs" httpd
# echo "this is failure one" > text.html
while checking not running container status # docker logs (CON ID)
data base need environment variable # docker run -itd --name db -e
MYSQL_ROOT_PASSWORD=sandy mysql:5.7
install wordpress # docker run -itd --name wp --link db:myapp -p "8081:80" wordpress
docker full details # docker inspect (con id)
(network)driver
bridge = when we create containers - this is run bridge driver - not mention auto create
container
host = mention and create container
none - not secure
connect network
# docker run -itd --name C1 alpine (old OS)
# docker run -itd --name C2 alpine
inside the C1 connect C2
# docker inspect (con id)
# docker exec -it (C1 con id) sh / # ping -c 5 (c2 IP)
# docker network create cus_net
# docker network ls
# docker run -itd --name A1 --network cus_net alpine
# docker run -itd --name A2 --network cus_net alpine
deafult network only connect the IP address can't connect container name
but when we create own network in that time we can connect IP and container ID
delete all stopped container # docker container prune
host network = can't use different application same port number web server
can't use port forwarding also
docker compose = same file use and create multiple contsiner by using script