Answers: <p>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.</p>
  
  <p>A simple example is:</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>You can parse that output or reformat with the <code>df</code> command as appropriate for your use case. The busybox version of <code>df</code> will have fewer options than you may be used to:</p>
  
  <pre><code>$ 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
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-04-10T05:09:22.937Z
Answers: Can you please explain this command `docker container run --rm -v "${volume_name}:/volume" -w /volume busybox df -P`
Answers: Aaditya R Krishnan
Answers: CC BY-SA 4.0
Answers: 2020-04-10T13:57:18.063Z
Answers: @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.
Answers: BMitch
Answers: CC BY-SA 4.0
Answers: 2020-04-09T14:17:12.373Z
Answers: 2020-04-09T14:17:12.373Z
Answers: BMitch
Body: <p>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.</p>
  
  <p>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.</p>
  
  <p>I tried using the <code>docker system df -v</code> But it showing all details.</p>
  
  <p>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.</p>
  
Comments: CC BY-SA 4.0
Comments: 2020-04-09T13:51:10.287Z
Comments: Hi. Do you mean attached volumes? Are you want to monitor container's native block device provided with `OverlayFS`?
Comments: Yasen
Tags: <docker><shell-script>
Title: How can I monitor docker volume usage?
UserDisplayName: Aaditya R Krishnan
ThreadText: # How can I monitor docker volume usage?
  
  (Asked by: username_0 on 2020-04-09)
  
  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.
  
  **Tags:** docker, shell-script
  
  > **Comments:**
  > **username_1**: Hi. Do you mean attached volumes? Are you want to monitor container's native block device provided with `OverlayFS`?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-04-09. Score: 2
  
  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
  
  ```
  
  > **Comments:**
  > **username_0**: Can you please explain this command `docker container run --rm -v "${volume_name}:/volume" -w /volume busybox df -P`  
  > **username_2**: @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.  
  
  ---
  
  