I'm aware of docker volume ls
and docker inspect -s
, but the former doesn't show size info and the latter, even though it has a --size
option, ignores it for volumes.
Is there something I'm missing?
I'm aware of docker volume ls
and docker inspect -s
, but the former doesn't show size info and the latter, even though it has a --size
option, ignores it for volumes.
Is there something I'm missing?
This:
docker volume inspect --format '{{ .Mountpoint }}' volumeNameHere
will return the mount point of the volume on your host. So, to get the size, it's just a matter of doing:
du -sh $(docker volume inspect --format '{{ .Mountpoint }}' volumeNameHere)
docker run --rm -v /:/vm-root alpine du -sH /vm-root/$(docker volume inspect --format '{{ .Mountpoint }}' volumeNameHere)
–
Palmore You can use:
docker system df -v
More info at https://docs.docker.com/engine/reference/commandline/system_df/
This:
docker volume inspect --format '{{ .Mountpoint }}' volumeNameHere
will return the mount point of the volume on your host. So, to get the size, it's just a matter of doing:
du -sh $(docker volume inspect --format '{{ .Mountpoint }}' volumeNameHere)
docker volume inspect --format '{{ .Mountpoint }}' my-volume-id
it returns /var/lib/docker/volumes/my-volume-id/_data
, but du -sh $(docker volume inspect --format '{{ .Mountpoint }}' my-volume-id)
returns No such file or directory
. –
Paw docker run --rm -v /:/vm-root alpine du -sH /vm-root/$(docker volume inspect --format '{{ .Mountpoint }}' volumeNameHere)
–
Palmore As pointed out by the answer of @MikeWu, one can see the size of Docker Volumes with:
docker system df -v
but one has to scroll around a bit to find the section Local Volumes space usage:
.
Using a piped sed
command like:
docker system df -v | sed -n '/VOLUME NAME/,/^ *$/p'
will help to improve the readability and reduce the output to the section of interest - by printing only from VOLUME NAME
until first empty line.
Building on Federkun's answer:
docker run --rm -v /:/vm-root alpine du -sH /vm-root/$(docker volume inspect --format '{{ .Mountpoint }}' volumeNameHere)
The first step of Federkun's answer worked for me and it returned something like this:
/var/lib/docker/volumes/f4678f...b87/_data
But when I tried
du -sh $(docker volume inspect --format '{{ .Mountpoint }}' volumeNameHere)
it returned a
du: /var/lib/docker/volumes/f4678f...b87/_data: No such file or directory
It turns out Docker works differently on macOS. According to this answer, before I can run the du -sh
command I must first screen
into the docker virtual machine used by MacOS. You can do so by running
sudo screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
and then you can run
du -sh /var/lib/docker/volumes/f4678f...
to finally get the volume size.
You can use Go templates to format the DiskUsageContext:
docker system df --verbose --format '{{ range .Volumes }}{{ .Name }} {{ .Size }}\n{{ end }}'
And if you want to check for a specific volume, and convert the human-readable values back to bytes, you can use awk
:
docker system df --verbose --format '{{ range .Volumes }}{{ .Name }} {{ .Size }}\n{{ end }}' | awk -v "volume_name=VOLUME_NAME" 'BEGIN { sizes["k"] = 1024; sizes["M"] = 1024^2; sizes["G"] = 1024^3; sizes[""] = 1; } match($0, "^" volume_name " ([0-9.]+)([kMG]?)B$", arr) { printf("%d\n", arr[1] * sizes[arr[2]]); }'
© 2022 - 2024 — McMap. All rights reserved.
docker volume inspect --format '{{ .Mountpoint }}' my-volume-id
it returns/var/lib/docker/volumes/my-volume-id/_data
, butdu -sh $(docker volume inspect --format '{{ .Mountpoint }}' my-volume-id)
returnsNo such file or directory
. – Paw