Docker Community Forums

Share and learn in the Docker community.

Docker daemon automatic create volumes at /var/lib/docker/volumes/


(Tien The PHAN) #1

Hello,

As I though, the volume only exist if we create it. But, amazing, I see many volume exists at > /var/lib/docker/volumes/. Although, I only create one volume before.

root@docker:~# docker container run -d --name redis -v 0e2881b08ee14e3da69633014c19eceb19b360909705b5f572ed666332c732f8:/data --network moby-counter redis:alpine
83a924d3cd45e55a05866336a944f5fff463975b49435b15b59a5474ea8d7528

and many volumes here

root@docker:~# ls -lrt /var/lib/docker/volumes/
total 84
drwxr-xr-x 3 root root 4096 Dec 5 13:49 9fad6fb1fa2138ed1219d0b7c3dd7a71802cd338a93acd37db8f78a96c605f6e
drwxr-xr-x 3 root root 4096 Dec 5 15:01 427eee233bf0cec8db03ce6c804196ad4ce718da91d08d404e8bd60f7ae1fa31
drwxr-xr-x 3 root root 4096 Dec 5 15:18 1dae8bb62887b89d33c02bb909aba4a9132bb919f6ddd150b3ad345ddce29566
drwxr-xr-x 3 root root 4096 Dec 5 15:19 92160653ef2556fef82e4b7c00f83b1d58c2d3547a31528324110a7ca51d2c01
drwxr-xr-x 3 root root 4096 Dec 5 16:15 41ee48ab795a34b8b180d1089f0f384b30a14c660b7ff9518cd9c04f501ed64c
drwxr-xr-x 3 root root 4096 Dec 5 17:13 0e2881b08ee14e3da69633014c19eceb19b360909705b5f572ed666332c732f8
drwxr-xr-x 3 root root 4096 Dec 5 17:41 81a11a16c13ce863b6040e7715d874069050626c6f1d7497e1f6eacd291767d0
drwxr-xr-x 3 root root 4096 Dec 5 17:46 54b61dc25c531a84b0cdef68b624c8f6a56c97793072a267deebea4cfc1bb468
drwxr-xr-x 3 root root 4096 Dec 5 17:53 1f5a0a9904becc2edbd321179f5a58c09533e70b42fa3a99cd5726c636c256ae
drwxr-xr-x 3 root root 4096 Dec 5 17:54 098fa96b9adfb87e18b49a24b5f65052afbc4985c2e5b6493d9626681113cbf0
drwxr-xr-x 3 root root 4096 Dec 20 10:00 019b3c0c65eb384641e90dc8163c316b89eac8bfec1bae4f79db3f7134017d3e
drwxr-xr-x 3 root root 4096 Dec 20 11:05 65ceb17c707a5f90190b84efc60a4931bdd01c71d25123d0ec0cd46e4b308fde
-rw------- 1 root root 65536 Dec 20 14:05 metadata.db
drwxr-xr-x 3 root root 4096 Dec 20 14:05 759df5e7c35b283a131fb98a04c70dc3dc0e0cb2ebdb1e60726cc6404218947a
root@docker:~#

So, does it create automatic by docker daemon? Could you please help me about this confusion.
Thank you so much.


(Tien The PHAN) #2

[Update] I have just deleted all of unused volume.

root@docker:/var/lib/docker/volumes# docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
019b3c0c65eb384641e90dc8163c316b89eac8bfec1bae4f79db3f7134017d3e
098fa96b9adfb87e18b49a24b5f65052afbc4985c2e5b6493d9626681113cbf0
81a11a16c13ce863b6040e7715d874069050626c6f1d7497e1f6eacd291767d0
1dae8bb62887b89d33c02bb909aba4a9132bb919f6ddd150b3ad345ddce29566
1f5a0a9904becc2edbd321179f5a58c09533e70b42fa3a99cd5726c636c256ae
759df5e7c35b283a131fb98a04c70dc3dc0e0cb2ebdb1e60726cc6404218947a
427eee233bf0cec8db03ce6c804196ad4ce718da91d08d404e8bd60f7ae1fa31
41ee48ab795a34b8b180d1089f0f384b30a14c660b7ff9518cd9c04f501ed64c
54b61dc25c531a84b0cdef68b624c8f6a56c97793072a267deebea4cfc1bb468
65ceb17c707a5f90190b84efc60a4931bdd01c71d25123d0ec0cd46e4b308fde
92160653ef2556fef82e4b7c00f83b1d58c2d3547a31528324110a7ca51d2c01

Total reclaimed space: 2.268kB
root@docker:/var/lib/docker/volumes# ls -lrt
total 44
drwxr-xr-x 3 root root 4096 Dec 5 13:49 9fad6fb1fa2138ed1219d0b7c3dd7a71802cd338a93acd37db8f78a96c605f6e
drwxr-xr-x 3 root root 4096 Dec 5 17:13 0e2881b08ee14e3da69633014c19eceb19b360909705b5f572ed666332c732f8
drwxr-xr-x 3 root root 4096 Dec 20 15:44 redis_data
-rw------- 1 root root 65536 Dec 20 15:57 metadata.db


#3

every VOLUME declared in a Dockerfile will result in a volume with random name beeing created, unless you map a named volume or host path to the container path.

Example:

Snippet of a Dockerfile:

VOLUME /data/test

If you don’t map a volume with -v ${named volume name or path}:/data/test you will end up with a new randomly named volume in /var/lib/docker/volumes.


(Tien The PHAN) #4

Thank you @meyay
But, I confused about some volumes existing what I didn’t create them. So I don’t know if the Docker daemon automatic created them as a default?


#5

The docker deamon does not create any default volumes, why would it?

As a test:

  1. clean everything: delete all your containers, prune all volumes. check /var/lib/docker/volumes for beeing empty.

  2. create a container

  3. inspect the container (docker inspect ${container id or name}) and take a look at the defined volumes

  4. check /var/lib/docker/volumes and see that the created volume(s) match the declared volumes seen with docker inspect

  5. delete the container with it’s volume(s) (docker rm --volumes ${container id or name})

  6. check /var/lib/docker/volumes to see that it’s empty

There is no magic involved here.