I'm planning to automate docker activities using python. However, I couldn't find any efficient command for monitoring docker volume. So now I wish to use shell commands for that and later it can be converted using subprocess in python.

My requirement is when I give a volume name then I need the used space, free space, and total space of that volume for finding the storage threshold of the same.

I tried using the docker system df -v But it showing all details.

For example, I give the volume name as my_volume then I need storage details of the same only. Hope everyone understood my requirement and excepting a helping hand from someone.

  • Hi. Do you mean attached volumes? Are you want to monitor container's native block device provided with OverlayFS?
    – Yasen
    Commented Apr 9, 2020 at 13:51

1 Answer 1


I'd recommend a temporary container for this. It will work on just about any version of docker, and supports named volumes with non-default settings, e.g. that store data on remote systems (e.g. NFS) or modify the bind mound settings to use another folder.

A simple example is:

$ docker container run --rm -v "${volume_name}:/volume" -w /volume busybox df -P .
Filesystem           1024-blocks    Used Available Capacity Mounted on
/dev/..........              898086280 350169736 502226484  41% /volume

You can parse that output or reformat with the df command as appropriate for your use case. The busybox version of df will have fewer options than you may be used to:

$ df --help
BusyBox v1.31.1 (2019-12-23 19:20:27 UTC) multi-call binary.

Usage: df [-PkmhTai] [-B SIZE] [FILESYSTEM]...

Print filesystem usage statistics

        -P      POSIX output format
        -k      1024-byte blocks (default)
        -m      1M-byte blocks
        -h      Human readable (e.g. 1K 243M 2G)
        -T      Print filesystem type
        -a      Show all filesystems
        -i      Inodes
        -B SIZE Blocksize
  • Can you please explain this command docker container run --rm -v "${volume_name}:/volume" -w /volume busybox df -P Commented Apr 10, 2020 at 5:09
  • @EdwardArrow the command runs a container based on the busybox image with the volume mounted. It then runs the df command in that volume directory. And when the df command completes the container exits and the --rm automatically deletes the container. See docker container run --help for more details on the options.
    – BMitch
    Commented Apr 10, 2020 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.