Docker Part5
Class 83rd DOCKER Part5 August 6th
Docker volume: Container to container data replication purpose using the docker volume
In docker we are running our application in containers and database container, if any network issues happen container will loss, docker manage create new container , but database container data will loss, too over come the issue we are using Docker volume
Forex:- application container -->database container
At the time of Container creation it self we have create docker volume mouth the containers
so that docker volume communicate the container1 and container2,synchroize the data ,we can protect one container Read only mode .
Data volume are independent container attached to that , if all containers removed, docker volume persist, we can attach new container to that
Practical
Step1: Create one EC2 instance Amazon Linux .
[root@ip-10-0-2-55 ~]# yum install docker -y && systemctl start docker
[root@ip-10-0-2-55 ~]# docker --version
Docker version 25.0.8, build 0bab007
Step2: Create container, here -v means volume given name of the volume1, mount the volume data in /tmp directory
[root@ip-10-0-2-55 ~]# docker run -itd --name container1 -v volume1:/tmp ubuntu
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
32f112e3802c: Pull complete
Digest: sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
Status: Downloaded newer image for ubuntu:latest
d250b2cd9d279417ef82e8cee6a623392a776b51318c9817527953f6d665a42e
--For this command to see list of containers
[root@ip-10-0-2-55 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d250b2cd9d27 ubuntu "/bin/bash" About a minute ago Up About a minute container1
--For this command to see list of volumes
[root@ip-10-0-2-55 ~]# docker volume ls
DRIVER VOLUME NAME
local volume1
Step3: As see above we have container mounted /tmp folder,
--Goto inside the container, Create some files in /tmp directory
[root@ip-10-0-2-55 ~]# docker exec -it container1 bash
root@d250b2cd9d27:/#
root@d250b2cd9d27:/# cd /tmp
root@d250b2cd9d27:/tmp# touch jenkins.txt Dockerfile one.yaml
root@d250b2cd9d27:/tmp# ls -lrt
total 0
-rw-r--r--. 1 root root 0 Aug 12 17:17 one.yaml
-rw-r--r--. 1 root root 0 Aug 12 17:17 jenkins.txt
-rw-r--r--. 1 root root 0 Aug 12 17:17 Dockerfile
--Click contrl+D exit from the container
[root@ip-10-0-2-55 ~]# yum docker insatll -y
No such command: docker. Please use /usr/bin/yum --help
It could be a YUM plugin command, try: "yum install 'dnf-command(docker)'"
[root@ip-10-0-2-55 ~]# yum insatll docker -y
No such command: insatll. Please use /usr/bin/yum --help
It could be a YUM plugin command, try: "yum install 'dnf-command(insatll)'"
[root@ip-10-0-2-55 ~]# yum install docker -y && systemctl start docker
Amazon Linux 2023 Kernel Livepatch repository 172 kB/s | 19 kB 00:00
Dependencies resolved.
====================================================================================================================================================
Package Architecture Version Repository Size
====================================================================================================================================================
Installing:
docker x86_64 25.0.8-1.amzn2023.0.5 amazonlinux 46 M
Installing dependencies:
container-selinux noarch 3:2.233.0-1.amzn2023 amazonlinux 55 k
containerd x86_64 2.0.5-1.amzn2023.0.2 amazonlinux 26 M
iptables-libs x86_64 1.8.8-3.amzn2023.0.2 amazonlinux 401 k
iptables-nft x86_64 1.8.8-3.amzn2023.0.2 amazonlinux 183 k
libcgroup x86_64 3.0-1.amzn2023.0.1 amazonlinux 75 k
libnetfilter_conntrack x86_64 1.0.8-2.amzn2023.0.2 amazonlinux 58 k
libnfnetlink x86_64 1.0.1-19.amzn2023.0.2 amazonlinux 30 k
libnftnl x86_64 1.2.2-2.amzn2023.0.2 amazonlinux 84 k
pigz x86_64 2.5-1.amzn2023.0.3 amazonlinux 83 k
runc x86_64 1.2.6-1.amzn2023.0.1 amazonlinux 3.7 M
Transaction Summary
====================================================================================================================================================
Install 11 Packages
Total download size: 77 M
Installed size: 292 M
Downloading Packages:
(1/11): container-selinux-2.233.0-1.amzn2023.noarch.rpm 1.4 MB/s | 55 kB 00:00
(2/11): iptables-libs-1.8.8-3.amzn2023.0.2.x86_64.rpm 8.3 MB/s | 401 kB 00:00
(3/11): iptables-nft-1.8.8-3.amzn2023.0.2.x86_64.rpm 4.5 MB/s | 183 kB 00:00
(4/11): libcgroup-3.0-1.amzn2023.0.1.x86_64.rpm 1.5 MB/s | 75 kB 00:00
(5/11): libnetfilter_conntrack-1.0.8-2.amzn2023.0.2.x86_64.rpm 2.1 MB/s | 58 kB 00:00
(6/11): libnfnetlink-1.0.1-19.amzn2023.0.2.x86_64.rpm 1.1 MB/s | 30 kB 00:00
(7/11): libnftnl-1.2.2-2.amzn2023.0.2.x86_64.rpm 3.0 MB/s | 84 kB 00:00
(8/11): pigz-2.5-1.amzn2023.0.3.x86_64.rpm 2.7 MB/s | 83 kB 00:00
(9/11): containerd-2.0.5-1.amzn2023.0.2.x86_64.rpm 48 MB/s | 26 MB 00:00
(10/11): runc-1.2.6-1.amzn2023.0.1.x86_64.rpm 13 MB/s | 3.7 MB 00:00
(11/11): docker-25.0.8-1.amzn2023.0.5.x86_64.rpm 46 MB/s | 46 MB 00:00
----------------------------------------------------------------------------------------------------------------------------------------------------
Total 76 MB/s | 77 MB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : runc-1.2.6-1.amzn2023.0.1.x86_64 1/11
Installing : containerd-2.0.5-1.amzn2023.0.2.x86_64 2/11
Running scriptlet: containerd-2.0.5-1.amzn2023.0.2.x86_64 2/11
Installing : pigz-2.5-1.amzn2023.0.3.x86_64 3/11
Installing : libnftnl-1.2.2-2.amzn2023.0.2.x86_64 4/11
Installing : libnfnetlink-1.0.1-19.amzn2023.0.2.x86_64 5/11
Installing : libnetfilter_conntrack-1.0.8-2.amzn2023.0.2.x86_64 6/11
Installing : iptables-libs-1.8.8-3.amzn2023.0.2.x86_64 7/11
Installing : iptables-nft-1.8.8-3.amzn2023.0.2.x86_64 8/11
Running scriptlet: iptables-nft-1.8.8-3.amzn2023.0.2.x86_64 8/11
Installing : libcgroup-3.0-1.amzn2023.0.1.x86_64 9/11
Running scriptlet: container-selinux-3:2.233.0-1.amzn2023.noarch 10/11
Installing : container-selinux-3:2.233.0-1.amzn2023.noarch 10/11
Running scriptlet: container-selinux-3:2.233.0-1.amzn2023.noarch 10/11
Running scriptlet: docker-25.0.8-1.amzn2023.0.5.x86_64 11/11
Installing : docker-25.0.8-1.amzn2023.0.5.x86_64 11/11
Running scriptlet: docker-25.0.8-1.amzn2023.0.5.x86_64 11/11
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /usr/lib/systemd/system/docker.socket.
Running scriptlet: container-selinux-3:2.233.0-1.amzn2023.noarch 11/11
Running scriptlet: docker-25.0.8-1.amzn2023.0.5.x86_64 11/11
Verifying : container-selinux-3:2.233.0-1.amzn2023.noarch 1/11
Verifying : containerd-2.0.5-1.amzn2023.0.2.x86_64 2/11
Verifying : docker-25.0.8-1.amzn2023.0.5.x86_64 3/11
Verifying : iptables-libs-1.8.8-3.amzn2023.0.2.x86_64 4/11
Verifying : iptables-nft-1.8.8-3.amzn2023.0.2.x86_64 5/11
Verifying : libcgroup-3.0-1.amzn2023.0.1.x86_64 6/11
Verifying : libnetfilter_conntrack-1.0.8-2.amzn2023.0.2.x86_64 7/11
Verifying : libnfnetlink-1.0.1-19.amzn2023.0.2.x86_64 8/11
Verifying : libnftnl-1.2.2-2.amzn2023.0.2.x86_64 9/11
Verifying : pigz-2.5-1.amzn2023.0.3.x86_64 10/11
Verifying : runc-1.2.6-1.amzn2023.0.1.x86_64 11/11
Installed:
container-selinux-3:2.233.0-1.amzn2023.noarch containerd-2.0.5-1.amzn2023.0.2.x86_64 docker-25.0.8-1.amzn2023.0.5.x86_64
iptables-libs-1.8.8-3.amzn2023.0.2.x86_64 iptables-nft-1.8.8-3.amzn2023.0.2.x86_64 libcgroup-3.0-1.amzn2023.0.1.x86_64
libnetfilter_conntrack-1.0.8-2.amzn2023.0.2.x86_64 libnfnetlink-1.0.1-19.amzn2023.0.2.x86_64 libnftnl-1.2.2-2.amzn2023.0.2.x86_64
pigz-2.5-1.amzn2023.0.3.x86_64 runc-1.2.6-1.amzn2023.0.1.x86_64
Complete!
[root@ip-10-0-2-55 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; preset: disabled)
Active: active (running) since Tue 2025-08-12 16:39:29 UTC; 3min 20s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Process: 5036 ExecStartPre=/bin/mkdir -p /run/docker (code=exited, status=0/SUCCESS)
Process: 5052 ExecStartPre=/usr/libexec/docker/docker-setup-runtimes.sh (code=exited, status=0/SUCCESS)
Main PID: 5057 (dockerd)
Tasks: 7
Memory: 29.1M
CPU: 330ms
CGroup: /system.slice/docker.service
└─5057 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --default-ulimit nofile=32768:65536
Aug 12 16:39:28 ip-10-0-2-55.eu-west-2.compute.internal systemd[1]: Starting docker.service - Docker Application Container Engine...
Aug 12 16:39:28 ip-10-0-2-55.eu-west-2.compute.internal dockerd[5057]: time="2025-08-12T16:39:28.592676147Z" level=info msg="Starting up"
Aug 12 16:39:28 ip-10-0-2-55.eu-west-2.compute.internal dockerd[5057]: time="2025-08-12T16:39:28.662669345Z" level=info msg="Loading containers: st>
Aug 12 16:39:29 ip-10-0-2-55.eu-west-2.compute.internal dockerd[5057]: time="2025-08-12T16:39:29.287917689Z" level=info msg="Loading containers: do>
Aug 12 16:39:29 ip-10-0-2-55.eu-west-2.compute.internal dockerd[5057]: time="2025-08-12T16:39:29.318821088Z" level=info msg="Docker daemon" commit=>
Aug 12 16:39:29 ip-10-0-2-55.eu-west-2.compute.internal dockerd[5057]: time="2025-08-12T16:39:29.318959956Z" level=info msg="Daemon has completed i>
Aug 12 16:39:29 ip-10-0-2-55.eu-west-2.compute.internal dockerd[5057]: time="2025-08-12T16:39:29.383068295Z" level=info msg="API listen on /run/doc>
Aug 12 16:39:29 ip-10-0-2-55.eu-west-2.compute.internal systemd[1]: Started docker.service - Docker Application Container Engine.
lines 1-22/22 (END)
Step4:
[root@ip-10-0-2-55 ~]# docker --version
Docker version 25.0.8, build 0bab007
[root@ip-10-0-2-55 ~]# docker run -itd --name container1 -v volume1:/tmp ubuntu
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
32f112e3802c: Pull complete
Digest: sha256:a08e551cb33850e4740772b38217fc1796a66da2506d312abe51acda354ff061
Status: Downloaded newer image for ubuntu:latest
d250b2cd9d279417ef82e8cee6a623392a776b51318c9817527953f6d665a42e
[root@ip-10-0-2-55 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d250b2cd9d27 ubuntu "/bin/bash" About a minute ago Up About a minute container1
[root@ip-10-0-2-55 ~]# docker volume ls
DRIVER VOLUME NAME
local volume1
[root@ip-10-0-2-55 ~]# docker exec -it container1 bash
root@d250b2cd9d27:/# touch jenkins.txt Dockerfile one.yaml
root@d250b2cd9d27:/# ls
Dockerfile bin boot dev etc home jenkins.txt lib lib64 media mnt one.yaml opt proc root run sbin srv sys tmp usr var
root@d250b2cd9d27:/# rm jenkins.txt Dockerfile one.yaml
root@d250b2cd9d27:/# cd /tmp
root@d250b2cd9d27:/tmp# touch jenkins.txt Dockerfile one.yaml
root@d250b2cd9d27:/tmp# ls -lrt
total 0
-rw-r--r--. 1 root root 0 Aug 12 17:17 one.yaml
-rw-r--r--. 1 root root 0 Aug 12 17:17 jenkins.txt
-rw-r--r--. 1 root root 0 Aug 12 17:17 Dockerfile
root@d250b2cd9d27:/tmp# ^C
root@d250b2cd9d27:/tmp#
exit
[root@ip-10-0-2-55 ~]#
Step5:
[root@ip-10-0-2-55 ~]# docker volume inspect volume1
[
{
"CreatedAt": "2025-08-12T16:46:07Z",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/volume1/_data",
"Name": "volume1",
"Options": null,
"Scope": "local"
}
]
Step6: As see below ,which was you have created these file in container,the files are automatically replicated in docker volume.
[root@ip-10-0-2-55 _data]# pwd
/var/lib/docker/volumes/volume1/_data
[root@ip-10-0-2-55 _data]# ls -lrt
total 0
-rw-r--r--. 1 root root 0 Aug 12 17:17 one.yaml
-rw-r--r--. 1 root root 0 Aug 12 17:17 jenkins.txt
-rw-r--r--. 1 root root 0 Aug 12 17:17 Dockerfile
Step7: Created some more files in docker volume
[root@ip-10-0-2-55 _data]# touch prabhu.txt naveen.txt sree.txt
[[root@ip-10-0-2-55 _data]# ls -lrt
total 0
-rw-r--r--. 1 root root 0 Aug 12 17:17 one.yaml
-rw-r--r--. 1 root root 0 Aug 12 17:17 jenkins.txt
-rw-r--r--. 1 root root 0 Aug 12 17:17 Dockerfile
-rw-r--r--. 1 root root 0 Aug 12 17:23 sree.txt
-rw-r--r--. 1 root root 0 Aug 12 17:23 prabhu.txt
-rw-r--r--. 1 root root 0 Aug 12 17:23 naveen.txt
[root@ip-10-0-2-55 _data]#
Step8: See automatically new files(prabhu,naveen,sree) coming to container1
[root@ip-10-0-2-55 _data]# docker exec -it container1 bash
root@d250b2cd9d27:/# cd /tmp
root@d250b2cd9d27:/tmp# ls -lrt
total 0
-rw-r--r--. 1 root root 0 Aug 12 17:17 one.yaml
-rw-r--r--. 1 root root 0 Aug 12 17:17 jenkins.txt
-rw-r--r--. 1 root root 0 Aug 12 17:17 Dockerfile
-rw-r--r--. 1 root root 0 Aug 12 17:23 sree.txt
-rw-r--r--. 1 root root 0 Aug 12 17:23 prabhu.txt
-rw-r--r--. 1 root root 0 Aug 12 17:23 naveen.txt
Step9: See Above Container1 amounted /tmp folder
volume1 /var/lib/docker/volumes/volume1/_data
Both will synchronize, Now planning create Colntainer2
[root@ip-10-0-2-55 _data]# docker run -itd --name container2 --mount src=volume1,destination=/opt ubuntu
2c55ceee626d0e51f9c7821e59811923e5428a0bdeb23c7302399cdd39b404cb
Step10: Go to inside the container
[root@ip-10-0-2-55 _data]# docker exec -it container2 bash
root@2c55ceee626d:/#
See now automatically files created these coming from docker volume
root@2c55ceee626d:/# cd /opt
root@2c55ceee626d:/opt# ls
Dockerfile jenkins.txt naveen.txt one.yaml prabhu.txt sree.txt
Step11: now planning create some file in container2 and need to check these file are coming to container1 or not
Containter2 (vinay.txt srikanth.txt mustafa.txt) these file created
root@2c55ceee626d:/opt# touch vinay.txt srikanth.txt mustafa.txt
root@2c55ceee626d:/opt# ls
Dockerfile jenkins.txt mustafa.txt naveen.txt one.yaml prabhu.txt sree.txt srikanth.txt vinay.txt
Ctrl+D exit form the container
--As see below container1 automatically (vinay.txt srikanth.txt mustafa.txt) these file are came from docker volume
[root@ip-10-0-2-55 _data]# docker exec -it container1 bash
root@d250b2cd9d27:/# cd /tmp
root@d250b2cd9d27:/tmp# ls
Dockerfile jenkins.txt mustafa.txt naveen.txt one.yaml prabhu.txt sree.txt srikanth.txt vinay.txt
Step12 : Even though ,Containers remove the docker volume should be present
Delete containers
[root@ip-10-0-2-55 _data]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c55ceee626d ubuntu "/bin/bash" 8 minutes ago Up 8 minutes container2
d250b2cd9d27 ubuntu "/bin/bash" About an hour ago Up About an hour container1
[root@ip-10-0-2-55 _data]# docker rm -f container1 container2
container1
container2
[root@ip-10-0-2-55 _data]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
See Volume should be present
[root@ip-10-0-2-55 _data]# docker volume ls
DRIVER VOLUME NAME
local volume1
Step13: Docker volume present in this directory ,as you see
volumes are stored in this directory
image are images stored in this directory
[root@ip-10-0-2-55 docker]# pwd
/var/lib/docker
[root@ip-10-0-2-55 docker]# ls
buildkit containers engine-id image network overlay2 plugins runtimes swarm tmp volumes
Step14: These volume1 our volume1 it has _data
[root@ip-10-0-2-55 volume1]# pwd
/var/lib/docker/volumes/volume1
[root@ip-10-0-2-55 volume1]# ls -lrt
total 0
drwxrwxrwt. 2 root root 167 Aug 12 18:10 _data
Step15:as see our data exist in our volume ,even containers deleted
[root@ip-10-0-2-55 _data]# pwd
/var/lib/docker/volumes/volume1/_data
[root@ip-10-0-2-55 _data]# ls -lrt
total 0
-rw-r--r--. 1 root root 0 Aug 12 17:17 one.yaml
-rw-r--r--. 1 root root 0 Aug 12 17:17 jenkins.txt
-rw-r--r--. 1 root root 0 Aug 12 17:17 Dockerfile
-rw-r--r--. 1 root root 0 Aug 12 17:23 sree.txt
-rw-r--r--. 1 root root 0 Aug 12 17:23 prabhu.txt
-rw-r--r--. 1 root root 0 Aug 12 17:23 naveen.txt
-rw-r--r--. 1 root root 0 Aug 12 18:10 vinay.txt
-rw-r--r--. 1 root root 0 Aug 12 18:10 srikanth.txt
-rw-r--r--. 1 root root 0 Aug 12 18:10 mustafa.txt
Step16: Already existing containers ,we can not attach the our volume ,
only possible at time of container creation time we have create the volume or exiting volume amount the volume.
Create the Volume separately also
[root@ip-10-0-2-55 _data]# docker volume create myapp
myapp
[root@ip-10-0-2-55 _data]# docker volume ls
DRIVER VOLUME NAME
local myapp
local volume1
Step17: Now planning to put the data to the volume
[root@ip-10-0-2-55 _data]# cd /var/lib/docker/volumes/myapp/_data
[root@ip-10-0-2-55 _data]# pwd
/var/lib/docker/volumes/myapp/_data
[root@ip-10-0-2-55 _data]# ls
Step18: files created in volume
[root@ip-10-0-2-55 _data]# touch app.java index.html styles.css
[root@ip-10-0-2-55 _data]# ls
app.java index.html styles.css
Step19: Now planning create container mount the volume
[root@ip-10-0-2-55 _data]# docker run -itd --name container3 --mount src=myapp,destination=/tmp ubuntu
fceb36fafe007bacad08130810a39d90302efae006b25ae0e2a23726c68fb654
Container3 is up ,go to inside check data exist or not
[root@ip-10-0-2-55 _data]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fceb36fafe00 ubuntu "/bin/bash" 29 seconds ago Up 28 seconds container3
Step20: File are came from docker volume to new container mounted /tmp folder
[root@ip-10-0-2-55 _data]# docker exec -it container3 bash
root@fceb36fafe00:/# cd /tmp
root@fceb36fafe00:/tmp# ls
app.java index.html styles.css
With out docker volume we can amount container host to container
Step1: Create one directory ,now these file mount to container
[ec2-user@ip-10-0-2-55 ~]$ sudo -i
[root@ip-10-0-2-55 ~]# mkdir swiggy
[root@ip-10-0-2-55 ~]# cd swiggy
[root@ip-10-0-2-55 swiggy]# touch index.jsp app.py scripts.sh
[root@ip-10-0-2-55 swiggy]# pwd
/root/swiggy
[root@ip-10-0-2-55 swiggy]# ls
app.py index.jsp scripts.sh
Step2: See below we have created container4 ,if directory not exist it will create new directory
pwd is present working directory copy the files to new directory
[root@ip-10-0-2-55 swiggy]# docker run -itd --name container4 -v $(pwd):/vakatisubbu/docker/ ubuntu
7d6cf0703787277bf2d8f5e649389d27d61cbb18c63c112237be0b71663f6e9c
As see files are came to directory
[root@ip-10-0-2-55 swiggy]# docker exec -it container4 bash
root@7d6cf0703787:/# cd /vakatisubbu/docker/
root@7d6cf0703787:/vakatisubbu/docker# ls
app.py index.jsp scripts.sh
Step3: planning create some file to container4 new directory, need to check ,local host /swiggy folder
file are coming or not
root@7d6cf0703787:/vakatisubbu/docker# touch dockfile jenkins one.yaml
root@7d6cf0703787:/vakatisubbu/docker# ls
app.py dockfile index.jsp jenkins one.yaml scripts.sh
root@7d6cf0703787:/vakatisubbu/docker#
exit
Step4: As see file are coming
[root@ip-10-0-2-55 swiggy]# ls
app.py dockfile index.jsp jenkins one.yaml scripts.sh
Real time examples
Step1: remove the existing containers
[root@ip-10-0-2-55 swiggy]# docker rm -f container4 container3
Step2: remove the existing volumes
[root@ip-10-0-2-55 swiggy]# docker volume rm myapp volume1
myapp
volume1
[root@ip-10-0-2-55 swiggy]# docker volume ls
DRIVER VOLUME NAME
Step3: Create some file to volume
[root@ip-10-0-2-55 swiggy]# docker volume create swiggy
swiggy
[root@ip-10-0-2-55 docker]# cd /var/lib/docker/volumes/swiggy/_data
[root@ip-10-0-2-55 _data]# ls
[root@ip-10-0-2-55 _data]# vi index.html
[root@ip-10-0-2-55 _data]# cat index.html
<h1> Welcome to Swiggy app </h1>
Step4: Now planning to mount the container these data volume, here nginx is image
[root@ip-10-0-2-55 _data]# docker run -itd --name container1 -p 1111:80 --mount src=swiggy,destination=/usr/share/nginx/html nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
59e22667830b: Pull complete
140da4f89dcb: Pull complete
96e47e70491e: Pull complete
2ef442a3816e: Pull complete
4b1e45a9989f: Pull complete
1d9f51194194: Pull complete
f30ffbee4c54: Pull complete
Digest: sha256:84ec966e61a8c7846f509da7eb081c55c1d56817448728924a87ab32f12a72fb
Status: Downloaded newer image for nginx:latest
8060c2c3416419f05ce44cdde47143a5beffe883b14fb2b50d673627e1ce9078
Step5:
Step6: Now we planning to change the text ,in volume in index.html
automatically will change nginx file path
[root@ip-10-0-2-55 _data]# pwd
/var/lib/docker/volumes/swiggy/_data
[root@ip-10-0-2-55 _data]# cat index.html
<h1> Welcome to Swiggy app Subbu </h1>
Project (Host to container)
Step1: Git installation completed
yum install git -y
Step2: clone the sample index.html page git project to local
[root@ip-10-0-2-55 ~]# git clone https://github.com/Vakatisubbu/website.git
Cloning into 'website'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (3/3), done.
Step2: now application need to check deployed or not
[root@ip-10-0-2-55 website]# docker run -itd --name container2 -p 2222:80 -v "$(pwd)":/usr/share/nginx/html nginx
8c637a5a57a3c500716bcdeae77589d6b8b2010b32d91804fa5acb258c9557fe
Step3: Application deployed successfully.
Now we are planning to do integrate docker services
Step1:
Docker Swarm , here we have taken only one server
[ec2-user@ip-10-0-2-55 ~]$ sudo -i
[root@ip-10-0-2-55 ~]# docker swarm init
Swarm initialized: current node (1sctotlqzvf76or2iipcjw097) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-4vianq32px0bttucbwq3fse7vdk8u3peaabtlg9kda20ubb3xb-crbohnev80p7knr5p5ahgi3pj 10.0.2.55:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
Step2: Two containers are created, both container same application page is running
[root@ip-10-0-2-55 ~]# docker service create --name website --replicas 2 --publish 3333:80 --mount src=swiggy,destination=/usr/share/nginx/html/ nginx
ohdb5kciwvt9jhdbz47lumiwy
overall progress: 2 out of 2 tasks
1/2: running [==================================================>]
2/2: running [==================================================>]
verify: Service converged
These below two container just created
[root@ip-10-0-2-55 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5a03d87798ed nginx:latest "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp website.1.jc21ky4sf0ooitn573lm3ys7d
8d04a9aa8f55 nginx:latest "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp website.2.lz11fgnhpaar743b230gi161f
Step3: Need to check whether application 3333 working fine or not
Step4: Now planning add some text in data volume
[root@ip-10-0-2-55 _data]# vi index.html
[root@ip-10-0-2-55 _data]# pwd
/var/lib/docker/volumes/swiggy/_data
[root@ip-10-0-2-55 _data]# cat index.html
<h1> Welcome to Swiggy app Subbu </h1>
<h1> Welcome to Swiggy Transactions </h1>
<h1> Welcome to Swiggy Orders </h1>
<h1> Welcome to Swiggy Delivered </h1>
Step5: Updated successfully.
How help docker command
For List of Images
[root@ip-10-0-2-55 _data]# docker image
Usage: docker image COMMAND
Manage images
Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Download an image from a registry
push Upload an image to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.
For List of Network
[root@ip-10-0-2-55 _data]# docker network
Usage: docker network COMMAND
Manage networks
Commands:
connect Connect a container to a network
create Create a network
disconnect Disconnect a container from a network
inspect Display detailed information on one or more networks
ls List networks
prune Remove all unused networks
rm Remove one or more networks
Run 'docker network COMMAND --help' for more information on a command.
For List of volume
[root@ip-10-0-2-55 _data]# docker volume
Usage: docker volume COMMAND
Manage volumes
Commands:
create Create a volume
inspect Display detailed information on one or more volumes
ls List volumes
prune Remove unused local volumes
rm Remove one or more volumes
update Update a volume (cluster volumes only)
Run 'docker volume COMMAND --help' for more information on a command.
Reference :Document with examples
https://docker77.hashnode.dev/docker-volumes-with-real-time-examples
--Thanks
No comments:
Post a Comment