Feedback

Chat Icon

Painless Docker - 2nd Edition

A Comprehensive Guide to Mastering Docker and its Ecosystem

Docker Volumes & Data Management
41%

Dangling Volumes

A dangling volume is a volume that's no longer associated with any container. While the container is gone, the volume remains on the host's disk, consuming space.

To list all dangling volumes, use the following filter:

docker volume ls -f dangling=true

To calculate the total size of these volumes, we can use a script.

total_size=0

# Loop through each dangling volume ID
for volume in $(docker volume ls -qf dangling=true); do
    # Get the host mountpoint of the volume
    mountpoint=$(docker volume inspect "$volume" --format '{{ .Mountpoint }}')

    # Calculate the size in Kilobytes (k)
    # 2>/dev/null handles cases where the path might be inaccessible
    size=$(sudo du -sk "$mountpoint" 2>/dev/null | cut -f1)

    if [

Painless Docker - 2nd Edition

A Comprehensive Guide to Mastering Docker and its Ecosystem

Enroll now to unlock all content and receive all future updates for free.

Unlock now  $31.99$25.59

Hurry! This limited time offer ends in:

To redeem this offer, copy the coupon code below and apply it at checkout:

Learn More