Skip to content

Instantly share code, notes, and snippets.

@aburaihan-dev
Created December 19, 2023 08:53
Show Gist options
  • Save aburaihan-dev/8805c721e8763f70b215c90effec2bb9 to your computer and use it in GitHub Desktop.
Save aburaihan-dev/8805c721e8763f70b215c90effec2bb9 to your computer and use it in GitHub Desktop.
This Bash script provides a quick overview of the sizes of Docker volumes using the du (disk usage) command. It iterates through all Docker volumes, retrieves their mountpoints, and calculates and prints their sizes in a human-readable format. Useful for monitoring and managing disk usage in Docker environments.
#!/bin/bash
# Get a list of all Docker volume names
volume_names=$(docker volume ls --quiet)
# Iterate through each volume and print its name and size
for volume_name in $volume_names; do
volume_path=$(docker volume inspect --format '{{ .Mountpoint }}' $volume_name)
volume_size=$(du -sh $volume_path | cut -f1)
echo "Volume: $volume_name, Size: $volume_size"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment