- Create docker volume let us name it as 'testvolume'
- List all available volumes in the host machine
- Run an alpine container (name it as 'alpine1') in interactive-mode by attaching volume (i.e. 'testvolume' ) to the container 'home' folder
- Enter into “alpine1” container; go to home folder and create a file called “testfile.txt” with sample text; exit from alpine1 container
- Run an alpine container (name it as 'alpine2' ) in interactive-mode by attaching same volume i.e. 'testvolume' to the container 'home' folder
- Enter inside “alpine2” container; go to home folder and check the file “testfile.txt” with content ; exit from alpine2 container
- Delete alpine1 and alpine2 containers
- Run an alpine container (name it as 'alpine3' ) in interactive-mode by attaching same volume i.e. 'testvolume' to the container 'home' folder
- Enter into “alpine3” container; go to home folder and check the file “testfile.txt” with content ; exit from alpine3 container
- Observe and experience the benefits of Docker Volume
Step 1:
> docker volume create testvolume
Step 2:
> docker volume ls
Step 3:
> docker run -it
-v testvolume:/home
--name alpine1 alpine sh (or)
> docker run -it
--mount type=volume,source=testvolume,target=/home
--name alpine1 alpine sh
Step 4:
/# cd home
/home # echo "hello world" > testfile.txt
Step 5:
> docker run -it
-v testvolume:/home
--name alpine2 alpine sh
Step 6:
/# cd home
/home # ls
Step 7:
> docker rm -f alpine1 alpine 2
Step 8:
> docker run -it -v testvolume:/home --name alpine3 alpine sh
Step 9:
/# cd home
/home # ls
Step 10:
- Volumes are easier to back up or migrate than bind mounts
- Volumes work on both Linux and Windows containers
- Volumes can be stored on remote hosts or cloud providers
- Volumes are managed by Docker. So, user can't be alter the content directly
Happy Coding :)
No comments:
Post a Comment