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/
1
/
2
Docker Advance Tutorial | Part 1 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 2 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 3 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 4 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 5 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 6 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 7 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 8 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 9 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 10 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 11 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 13 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 14 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 15 out 16 | — By DevOpsSchool
Docker Advance Tutorial | Part 16 out 16 | — By DevOpsSchool
1
/
2
Latest posts by Rajesh Kumar (see all)
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024