Docker Volume

Posted by

Human –> Docker pull image –>Docker client –> RESTAPI –> docker Deamon (will check local Repo(/Var/lib/docker) – if there – do rest / if not there – Download repo from registry

Where image layers stored

Path – /var/lib/docker

storage – /overlay2

where image meta data stored

/var/lib/docker /image

Docker Volumn

Go to /Var/lib/docker/volumes

root@Jami:/home/jami/Docker# docker volumn ls

root@Jami:/home/jami/Docker# docker volume create dev
dev

root@Jami:/# docker run -itd -v dev:/opt/dev ubuntu
fc90bdeb9b516ea09b85e5b2420a8a1cfc768fd8a78371767c2078d267ffeea9

root@Jami:/var/lib/docker/volumes# pwd
/var/lib/docker/volumes
root@Jami:/var/lib/docker/volumes#

root@Jami:/var/lib/docker/volumes/dev/_data# pwd
/var/lib/docker/volumes/dev/_data
root@Jami:/var/lib/docker/volumes/dev/_data#

create file and its also present outside container under location /var/lib/docker/volumes/dev/_data

root@Jami:/var/lib/docker/volumes/dev/_data# docker exec fc90bdeb9b51 touch /opt/dev/file1
root@Jami:/var/lib/docker/volumes/dev/_data# ls
file1
root@Jami:/var/lib/docker/volumes/dev/_data# docker exec fc90bdeb9b51 touch /opt/dev/file2
root@Jami:/var/lib/docker/volumes/dev/_data# docker exec fc90bdeb9b51 touch /opt/dev/file3
root@Jami:/var/lib/docker/volumes/dev/_data# ls
file1 file2 file3

root@Jami:/var/lib/docker/volumes/dev/_data# docker exec fc90bdeb9b51 ls /opt/dev
file1
file2
file3

stop and remove container but data still persist

root@Jami:/var/lib/docker/volumes/dev/_data# docker stop fc90bdeb9b51
fc90bdeb9b51
root@Jami:/var/lib/docker/volumes/dev/_data# docker rm fc90bdeb9b51
fc90bdeb9b51
root@Jami:/var/lib/docker/volumes/dev/_data# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
root@Jami:/var/lib/docker/volumes/dev/_data# ls
file1 file2 file3
root@Jami:/var/lib/docker/volumes/dev/_data#

Mount this volumn other container

root@Jami:/var/lib/docker/volumes/dev/_data# docker run -itd -v dev:/opt/dev ubuntu
25c90130ad315c27cdf31fb85fbb2335cba8c7746bfbdbc849fad9f7b7dd1d9e
root@Jami:/var/lib/docker/volumes/dev/_data# ls
file1 file2 file3
root@Jami:/var/lib/docker/volumes/dev/_data# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
25c90130ad31 ubuntu “/bin/bash” 12 seconds ago Up 11 seconds zealous_blackburn
root@Jami:/var/lib/docker/volumes/dev/_data# docker exec 25c90130ad31 ls /opt/dev
file1
file2
file3
root@Jami:/var/lib/docker/volumes/dev/_data#

also can mount 2 volumn to one container

root@Jami:/var/lib/docker/volumes/dev/_data# docker run -itd -v dev:/opt/dev -v qa:/opt/jami ubuntu
6de4fe01ac443bcccc1df1ea62acb6124d55908e893b506676fb5a7c3686eea0
root@Jami:/var/lib/docker/volumes/dev/_data# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6de4fe01ac44 ubuntu “/bin/bash” 9 seconds ago Up 8 seconds objective_albattani
25c90130ad31 ubuntu “/bin/bash” 3 minutes ago Up 3 minutes zealous_blackburn

only one we can see if doing df -kh and other can see if going to path
root@Jami:/var/lib/docker/volumes/dev/_data# docker exec 6de4fe01ac44 df -kh
Filesystem Size Used Avail Use% Mounted on
overlay 24G 13G 11G 55% /
tmpfs 64M 0 64M 0% /dev
shm 64M 0 64M 0% /dev/shm
/dev/sda3 24G 13G 11G 55% /opt/dev
tmpfs 5.4G 0 5.4G 0% /proc/asound
tmpfs 5.4G 0 5.4G 0% /proc/acpi
tmpfs 5.4G 0 5.4G 0% /proc/scsi
tmpfs 5.4G 0 5.4G 0% /sys/firmware
root@Jami:/var/lib/docker/volumes/dev/_data# docker exec 6de4fe01ac44 ls /opt
dev
jami
root@Jami:/var/lib/docker/volumes/dev/_data#

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x