Introduction to the Docker Volumes

Introduction to the Docker volumes for beginner

source image:

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. While bind mounts are dependent on the directory structure of the host machine, volumes are completely managed by Docker. Volumes have several advantages over bind mounts:

  • Volumes are easier to back up or migrate than bind mounts.

In addition, volumes are often a better choice than persisting data in a container’s writable layer, because a volume does not increase the size of the containers using it, and the volume’s contents exist outside the lifecycle of a given container. source:

docker volume

Create docker volume:

sudo docker volume create test-volume

see volumes

sudo docker volume ls

see volume detail

sudo docker volume inspect test-volume

run container with volume

sudo docker run -d — name=nginxtest -v test-volume:/usr/share/nginx/html nginx:latest

see IP address container

sudo docker inspect nginxtest | grep -i ipaddress
docker inspect nginxtest

Test browsing app

curl http:

test app container IP

Create file index.html and move to source volume directory

sudo echo "This is from test-volume source directory." > index.htmlsudo mv index.html /var/lib/docker/volumes/test-volume/_data

Then test again

access the container IP

Run container with read only volume

sudo docker run -d — name=nginxtest-rovol -v test-volume:/usr/share/nginx/html:ro nginx:latest

view nginx container detail

nginxtest-rovol container detail

Let’s move on to part 2 volume driver is here.

reference :



Cloud DevOps Enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store