Using the default overlay
storage driver, a Docker volume doesn't have a "size" (all the volumes share space on the same filesystem). The only way to figure out the space consumed by the volume is by iterating over all the files in it and adding up their individual sizes. There are a couple ways to do this.
I think the easiest is just to mount the volumes. For example:
docker volume ls -q |
while read vol; do
echo "=== $vol ==="
docker run --rm -v "$vol:/data" alpine du -sh /data
done
If you really want to avoid docker run
, you could do something like this (note that we're using jq
to parse the JSON output from docker volume inspect
):
docker volume ls -q |
while read vol; do
mount=$(docker volume inspect "$vol" | jq -r '.[0].Mountpoint')
echo "=== $vol ==="
sudo du -sh "$mount"
done
I prefer the first solution, because it will work even if the docker daemon is running on a remote host or virtual machine. For example, the above will fail on either Windows or MacOS because on those systems, Docker is running a vm, so the volume paths won't be visible on the host when running du
.