Docker Complete
Docker Complete
Docker Complete
MICRO SERVICES: SINGLE APP -- > MULTIPLE SERVERS -- > MULTIPLE DATABASES
MICRO:
COST WILL BE HIGH
MAINTAINANCE
LIMITATIONS OF MONLITHIC:
1. SERVER PERFOMANCE
CONTAINERS:
SERVER = CONTAINER
PUBG:
APP: PLAYSTORE MAPS: INTERNET
DOCKER:
its a free and open-source platform.
docker will create containers.
we can create, run, and deploy our apps on containers.
its platform independent (native runs on Linux Distribution).
containers will use host resources (cpu, mem, ram, os)
docker will perform os level of VIRTUALIZATION called containerization.
year: 2013
developed by: Solomen Hykes and Sebastian Phal
language: go lang
ARCHITECTURE:
DOCKER CLIENT: its a way of interacting with docker (command -- > op)
DOCKER DAEMON: it manage all the docker components (images, cont, volumes, nlw)
DOCKER HOST: where we installed docker
DOCKER REGISTRY: it manages all the docker images on internet.
INSTALLATION:
yum install docker -y
systemctl start docker
systemctl status docker
ctrl p q
HISTORY:
1 yum install docker -y
2 docker version
3 systemctl start docker
4 systemctl status docker
5 docker version
6 docker images
7 docker search amazonlinux
8 docker pull amazonlinux
9 docker images
10 lsblk
11 cd
12 cd /
13 du -sh
14 docker run -it --name cont1 amazonlinux
15 docker ps
16 docker ps -a
17 docker stop cont1
18 docker ps
19 docker ps -a
20 docker start cont1
21 docker ps
22 docker kill cont1
23 history
===================================================================================
==========
OS LEVEL VIRTUALIZATION:
WORKING:
docker pull ubuntu
docker run -it --name cont1 ubuntu
apt update -y
apt install git maven apache2 tree -y
touch file{1..5}
COMPONENTS:
FROM : to base image (gives os)
RUN : to execute linux commands (image creation)
CMD : to execute linux commands (container creation)
ENTRYPOINT : high priority than cmd
COPY : to copy local files to conatainer
ADD : to copy Intenet files to conatainer
WORKDIR : to go desired folder
LABEL : to attach our tags/labels
ENV : variables which run inside conatiner (image)
ARGS : variables which run outside conatiner(containers)
VOLUME : used to create volume for conatiner
EXPOSE : used to give port number
EX: -1
FROM ubuntu
RUN apt update -y
RUN apt install git maven tree apache2 -y
ex-2:
FROM ubuntu
RUN apt update -y
RUN apt install git maven tree apache2 -y
CMD apt install default-jre -y
EX-3:
FROM ubuntu
RUN apt update -y
RUN apt install git maven tree apache2 -y
COPY index.html /tmp
ADD https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-
bin.tar.gz /tmp
EX-4:
FROM ubuntu
RUN apt update -y
RUN apt install git maven tree apache2 -y
COPY index.html /tmp
ADD https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-
bin.tar.gz /tmp
WORKDIR /tmp
LABEL author rahamshaik
EX-5:
FROM ubuntu
RUN apt update -y
RUN apt install git maven tree apache2 -y
COPY index.html /tmp
ADD https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-
bin.tar.gz /tmp
WORKDIR /tmp
LABEL author rahamshaik
ENV name vijay
ENV client swiggy
EX-6:
FROM ubuntu
RUN apt update -y
RUN apt install git maven tree apache2 -y
COPY index.html /tmp
ADD https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-
bin.tar.gz /tmp
WORKDIR /tmp
LABEL author rahamshaik
ENV name vijay
ENV client swiggy
VOLUME ["/volume1"]
EXPOSE 8080
COMMANDS:
docker ps -a -q : to list conatier ids
docker stop $(docker ps -a -q) : to stop all conatiners
docker rm $(docker ps -a -q) : to delete all conatiners
VOLUMES:
in docker, we use volumes to store the data.
volume is nothing but a folder inside a container.
we can share a volume from one container to another.
the volume contains the files which have data.
we can attach the single volume to multiple containers.
but at a time we can attach only one volume to one container.
volumes are decoupled (loosely attached)
if we delete the container volume will not be deleted.
METHOD-1:
DOCKER FILE:
FROM ubuntu
VOLUME ["/volume1"]
2. CLI:
3. VOLUME MOUNTING:
volume commands:
docker volume create volume3
docker volume ls
docker volume inspect volume3
cd /var/lib/docker/volumes/volume3/_data
touch python{1..10}
ll
docker run -it --name cont5 --mount source=volume3,destination=/volume3 ubuntu
touch raham{1..10}
docker inspect cont6
docker volume inspect volume4
cp * /var/lib/docker/volumes/volume4/_data
5.
touch raham{1..10}
cp * /home/ec2-user
docker run -it --name cont12 -v /home/ec2-user:/abcd ubuntu
SYSTEM COMMANDS:
docker system df : show docker components resource utilization
docker system df -v : show docker components resource utilization individually
docker system prune : to remove unused docker components
JENKINS SETUP:
docker run -it --name cont1 -p 8080:8080 jenkins/jenkins:lts
HISTORY:
1 docker --version
2 vim Dockerfile
3 docker build -t netflix:v1 .
4 docker images
5 docker run -it --name cont1 netflix:v1
6 docker ps -a
7 docker run -it --name cont2 --volumes-from cont1 --privileged=true ubuntu
8 docker run -it --name cont3 -v /volume2 ubuntu
9 docker run -it --name --volumes-from cont3 --privileged=true cont4
10 docker run -it --name cont4 --volumes-from cont3 --privileged=true ubuntu
11 docker volume create volume3
12 docker volume ls
13 docker volume inspect volume3
14 cd /var/lib/docker/volumes/volume3/_data
15 touch python{1..10}
16 ll
17 docker run -it --name cont5 --mount source=volume3 destination=/volume3
ubuntu
18 docker run -it --name cont5 --mount source=volume3, destination=/volume3
ubuntu
19 docker run -it --name cont5 --mount source=volume3, dest=/volume3 ubuntu
20* docker run -it --name cont5 --mount source=volume3,destination=/volume3
ubuntu cd
21 cd
22 docker volume create volume4
23 docker volume ls
24 docker volume inspect volume4
25 cd /var/lib/docker/volumes/volume4/_data
26 touch php{1..10}
27 docker run -it --name cont6 --mount source=volume4,destination=/volume4
ubuntu
28 ll
29 cd
30 touch raham{1..10}
31 ll
32 docker inspect cont6
33 docker volume inspect volume4
34 ll
35 cp * /var/lib/docker/volumes/volume4/_data
36 docker attach cont6
37 docker volume inspect volume4
38 ll
39 docker run -it --name cont7 -v /root=/abc ubuntu
40 docker run -it --name cont8 -v /root=abc ubuntu
41 docker run -it --name cont7 -v /abc ubuntu
42 docker run -it --name cont8 -v /abc ubuntu
43 docker run -it --name cont9 -v /abc ubuntu
44 ll
45 cp * /home/ec2-user/
46 cd /home/ec2-user/
47 ll
48 docker run -it --name cont10 -v /home/ec2-user/=abcd ubuntu
49 docker run -it --name cont11 --volume /home/ec2-user/=abcd ubuntu
50 docker run -it --name cont12 -v /home/ec2-user:abcd ubuntu
51 docker run -it --name cont12 -v /home/ec2-user:/abcd ubuntu
52 cd
53 docker system
54 docker system df
55 docker system df -v
56 docker volume create volume5
57 docker volume create volume6
58 docker system df -v
59 docker pull centos
60 docker pull amazonlinux
61 docker system prune
62 docker kill $(docker ps -a -q)
63 docker create network raham
64 docker network create raham
65 docker network create raham2
66 docker network create raham1
67 docker system prune
68 docker system events
69 docker run -it --name cont1 -p 8080:8080 jenkins/jenkins:lts
70 history
[root@ip-172-31-12-122 ~]#
====================================================================LINK:
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_form_icon
PROCESS:
CODE -- > BUILD (DOCKER FILE) -- > IMAGE -- > CONTAINER -- > APP
http://3.7.248.36:81/
vim Dockerfile
FROM ubuntu
RUN apt update -y
RUN apt install apache2 -y
COPY index.html /var/www/html
CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]
create index.html
DOCKER COMPOSE:
its a tool used to launch multiple conatiners.
we can create multiple conatiners on single hosts.
all of the services informatiom we are going to write on a file.
here we use docker-compose/compose file.
it will be on yaml format.
we use key-value pair (dictionary) (.yml or .yaml)
used to manage multiple servivces with help of a file.
SETUP:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-
compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
ls /usr/local/bin/
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose version
vim docker-compose.yml
version: '3.8'
services:
movies:
image: movies:v1
ports:
- "81:80"
train:
image: train:v1
ports:
- "82:80"
dth:
image: dth:v1
ports:
- "83:80"
recharge:
image: recharge:v1
ports:
- "84:80"
Commands:
docker-compose up -d : to run all services
docker-compose down : to remove all services
docker-compose stop : to stop all services
docker-compose kill : to kill all services
docker-compose rm : to remove all services which is on stopped state
docker-compose start : to start all services
docker-compose pause : to pause all services
docker-compose unpause : to unpause all services
docker-compose images : to get all images managed by compose file
docker-compose ps -a : to get all containers managed by compose file
docker-compose logs : to get all logs managed by compose file
docker-compose scale dth=10: to create 10 containers of dth
docker-compose top : to get all process managed by conatiners on compose file
=================================
DOCKER HUB:
Its a central platfrom used to store docker images.
image we create on host then we will push them to dockerhub.
Once image is availabel on dockerhub we can use in any server.
we use repos to store images.
repo types: 1. public 2. private repo
ACCOUNT:
build a docker image with doker file.
docker login: username and password
DOCKER SWARM:
SETUP:
1. create 3 servers (1=manager 2=worker) (all traffic is must)
yum install docker -y
systemctl start docker
systemctl status docker
SERVICES:
its a way of exposing the application in docker.
with services we can create multiple copies of same container.
with services we can distribute the containers to all servers.
HISTORY:
1 docker imgages
2 docker images
3 docker swarm init
4 docker node ls
5 docker run -itd --name cont1 jayaprakashsairam05/movies:latest
6 docker ps -a
7 docker kill cont1
8 docker rm cont1
9 docker service create --name movies --replicas=3 --publish 81:80
jayaprakashsairam05/movies:latest
10 docker ps -a
11 docker service create --name train --replicas=6 --publish 82:80
jayaprakashsairam05/train:latest
12 docker ps -a
13 docker service ls
14 docker ps -a
15 docker service ls
16 docker service ps train
17 docker service inspect train
18 docker service ls
19 docker service scale train=10
20 docker service ls
21 docker service ps train
22 docker service scale train=6
23 docker service rollback train
24 docker service rm train
25 docker service ls
26 docker ps -a
27 docker kill 3d6965f5a234
28 docker ps -a
29 docker kill 159af68bfd56
30 docker ps -a
31 docker node ls
32 docker node rm c2ldr2jfatw9p8s4uqzrf329h
33 docker node ls
34 docker node rm uhru8isgfco57di11azvbk2c9
35 docker node ls
36 docker node rm 3tm927qkvrt8sdr7sz7gprs7t
37 docker node ls
38 docker node rm 3tm927qkvrt8sdr7sz7gprs7t
39 docker node ls
40 docker swarm joint-token manager
41 docker swarm join-token manager
42 history
[root@manager ~]#
=============================================
PORTAINER:
it is a container organizer, designed to make tasks easier, whether they are
clustered or not.
abel to connect multiple clusters, access the containers, migrate stacks between
clusters
it is not a testing environment mainly used for production routines in large
companies.
Portainer consists of two elements, the Portainer Server and the Portainer Agent.
Both elements run as lightweight Docker containers on a Docker engine
SETUP:
Must have swarm mode and all ports enable with docker engine
curl -L https://downloads.portainer.io/ce2-16/portainer-agent-stack.yml -o
portainer-agent-stack.yml
docker stack deploy -c portainer-agent-stack.yml portainer
docker ps
public-ip of swamr master:9000
DOCKER NETWORKING:
Docker networks are used to make a communication between the multiple containers
that are running on same or different docker hosts. We have different types of
docker networks.
Bridge Network
Host Network
None network
Overlay network
BRIDGE NETWORK: It is a default network that container will communicate with each
other within the same host.
HOST NETWORK: When you Want your container IP and ec2 instance IP same then you use
host network
NONE NETWORK: When you don’t Want The container to get exposed to the world, we use
none network. It will not provide any network to our container.
OVERLAY NETWORK: Used to communicate containers with each other across the multiple
docker hosts.
RESOURCE MANAGEMENT:
continers are going to use host resources. (cpu, mem and ram)
we need to limit that resoure utilization.
by default containers are not having limts.