Hi, I’ll bet those are volumes from all of the containers you have been running.
Run a docker volume ls
command to display them.
Docker does not remove volumes when containers are stopped or removed, because it does not want to erase any persistent data. It does not know what volumes are “critical” to you.
If you don’t create volumes with “names” then Docker generates those cryptic names.
And you can run a new container and mount an existing volume.
But you would have to keep track of cryptic names.
So I recommend you create volumes with names that “make sense”,
Examples
Start some containers with un-named volumes.
🐳 vagrant@172.16.129.75:[~] $ docker container run -it --detach --name mysql1 --env MYSQL_RANDOM_ROOT_PASSWORD=true -v /vol:/var/lib mysql
8a4b3a7ab5f49e42a9f50785852458a421da2c03a58548fc3322ff3b0e8db707
🐳 vagrant@172.16.129.75:[~] $ docker container run -it --detach --name mysql2 --env MYSQL_RANDOM_ROOT_PASSWORD=true -v /vol:/var/lib mysql
5779654bd964a6649eef870f357767e0634d5552e8d809ed4a9a60cacedbeed4
🐳 vagrant@172.16.129.75:[~] $ docker container run -it --detach --name mysql3 --env MYSQL_RANDOM_ROOT_PASSWORD=true -v /vol:/var/lib mysql
af5360e6c1c35eeff340e46fbaff0440f67a3976dfb5d02c44311b8f9cb7eb1b
Display the volumes
🐳 vagrant@172.16.129.75:[~] $ docker volume ls
DRIVER VOLUME NAME
local 1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
local 3e5d4e5da3afeee04aa07cdb182ea290b58c6dda293a30b34127b93015b46114
local 6def49430229b45efc30552a27eafae86d5aa2d5b54302c7d871b604fba3b7bc
Create a volume with a name
🐳 vagrant@172.16.129.75:[~] $ docker volume create my-vol1
my-vol1
Now start a container and mount that named volume.
🐳 vagrant@172.16.129.75:[~] $ docker container run -it --detach --name mysql4 --env MYSQL_RANDOM_ROOT_PASSWORD=true -v my-vol1:/var/lib mysql
a05cde8a8e30da00270f8a4953136dbb027f24cea6d9cdf0879787b78358d012
Display the volumes
🐳 vagrant@172.16.129.75:[~] $ docker volume ls
DRIVER VOLUME NAME
local 1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
local 3e5d4e5da3afeee04aa07cdb182ea290b58c6dda293a30b34127b93015b46114
local 6def49430229b45efc30552a27eafae86d5aa2d5b54302c7d871b604fba3b7bc
local 1984690157f0f8b097b9878a907dcb63394f67bca0c21a64b7256b5c149566bc
local my-vol1
Display volumes by ID only
🐳 vagrant@172.16.129.75:[~] $ docker volume ls -q
1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
3e5d4e5da3afeee04aa07cdb182ea290b58c6dda293a30b34127b93015b46114
6def49430229b45efc30552a27eafae86d5aa2d5b54302c7d871b604fba3b7bc
1984690157f0f8b097b9878a907dcb63394f67bca0c21a64b7256b5c149566bc
my-vol1
Try and delete all volumes. Can’t delete ones that are attached to running or stopped containers.
🐳 vagrant@172.16.129.75:[~] $ docker volume rm $(docker volume ls -q)
Error response from daemon: remove 1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637: volume is in use - [5779654bd964a6649eef870f357767e0634d5552e8d809ed4a9a60cacedbeed4]
Error response from daemon: remove 3e5d4e5da3afeee04aa07cdb182ea290b58c6dda293a30b34127b93015b46114: volume is in use - [8a4b3a7ab5f49e42a9f50785852458a421da2c03a58548fc3322ff3b0e8db707]
Error response from daemon: remove 6def49430229b45efc30552a27eafae86d5aa2d5b54302c7d871b604fba3b7bc: volume is in use - [af5360e6c1c35eeff340e46fbaff0440f67a3976dfb5d02c44311b8f9cb7eb1b]
Error response from daemon: remove 1984690157f0f8b097b9878a907dcb63394f67bca0c21a64b7256b5c149566bc: volume is in use - [a05cde8a8e30da00270f8a4953136dbb027f24cea6d9cdf0879787b78358d012]
Error response from daemon: remove my-vol1: volume is in use - [a05cde8a8e30da00270f8a4953136dbb027f24cea6d9cdf0879787b78358d012]
Hmm… how do I know which container is using this volume: 1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
?
Run a docker ps -a --filter
volume=1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
🐳 vagrant@172.16.129.75:[~] $ docker ps -a --filter volume=1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5779654bd964 mysql "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 3306/tcp, 33060/tcp mysql2
Remove the container.
🐳 vagrant@172.16.129.75:[~] $ docker container rm -f 5779654bd964
5779654bd964
Volume is still there, but not attached to a container, the container was removed.
This is your “problem”. You have lots of "orphaned un-named volumes.
🐳 vagrant@172.16.129.75:[~] $ docker ps -a --filter volume=1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Now I can remove the volume 1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
🐳 vagrant@172.16.129.75:[~] $ docker volume rm 1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
Display the volume 1e67d928913b5b55f512c921b2306be0f941a8bece50c0205729d14feba1b637
It’s gone.
🐳 vagrant@172.16.129.75:[~] $ docker volume ls -q
3e5d4e5da3afeee04aa07cdb182ea290b58c6dda293a30b34127b93015b46114
6def49430229b45efc30552a27eafae86d5aa2d5b54302c7d871b604fba3b7bc
1984690157f0f8b097b9878a907dcb63394f67bca0c21a64b7256b5c149566bc
my-vol1
Who is using my-vol1 ?
🐳 vagrant@172.16.129.75:[~] $ docker ps -a --filter volume=my-vol1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a05cde8a8e30 mysql "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 3306/tcp, 33060/tcp mysql4
Display all containers
🐳 vagrant@172.16.129.75:[~] $ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a05cde8a8e30 mysql "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 3306/tcp, 33060/tcp mysql4
af5360e6c1c3 mysql "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 3306/tcp, 33060/tcp mysql3
8a4b3a7ab5f4 mysql "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 3306/tcp, 33060/tcp mysql1
Remove all containers with force (removes running and stopped). Be careful, make sure you want this…
🐳 vagrant@172.16.129.75:[~] $ docker container rm -f $(docker container ls -q)
a05cde8a8e30
af5360e6c1c3
8a4b3a7ab5f4
You can also run a docker system prune --volumes
to remove all volumes that are not attached to containers.
Again be careful you don’t delete volumes you want to keep.
$ docker system prune --volumes
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all volumes not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N] y
Deleted Volumes:
1984690157f0f8b097b9878a907dcb63394f67bca0c21a64b7256b5c149566bc
3e5d4e5da3afeee04aa07cdb182ea290b58c6dda293a30b34127b93015b46114
6def49430229b45efc30552a27eafae86d5aa2d5b54302c7d871b604fba3b7bc
my-vol1
Total reclaimed space: 654.8MB