Simple Flow to Create Volume /john1
$ docker run -it -v /john1 busybox
$ cd john1
$ ls
$ touch file1
$ ls
CTRL + P + Q
$ docker ps
The volume is exist even you restarts.
$ docker restart cont_id
$ docker exec cont_id ls /john1
Lets build a image with predefined Volume
$ vi Dockerfile
FROM ubuntu
ADD file1 /john2/file
VOLUME /john2
CMD ["/bin/bash"]
$ docker build myimage1 .
$ docker images
$ docker run -it myimage1
$ ls
Mapping between Host Volume and Containers
$ docker run -it -v /home/vagrant/john3:/john3 myimage1
$ cd john3
$ ls
$ touch file5
$ exit
$ cd john3
$ ls
Senario 1 – Read only File Systems
$ docker run -it -v /home/vagrant/john3:/john3 myimage1
$ cd /john3
$ vi filex.txt # Try to save it and observe the output
Senario 2 – Map the Specific files between Host and Containers
$ docker run -it -v ~/.bash_history:/.bash_history myimage1
Lets clean up containers for clean next lab
$ docker kill $(docker ps -q)
$ docker rm $(docker ps -aq)
Senario 3 – Lets run the container with volume from another container volume
$ docker run -it -d --name cont1 -v /VolX myimage1
$ docker run -it --name cont2 --volumes-from cont myimage1
Locating a volume
docker inspect image_name # Look for mount section
More referencehttps://docs.docker.com/engine/tutorials/dockervolumes/

















I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND