Skip to content

Instantly share code, notes, and snippets.

@ismailkarsli
Created June 4, 2023 19:52
Show Gist options
  • Save ismailkarsli/dd71cd5ebb3b1a611ddb56b1bdc238c5 to your computer and use it in GitHub Desktop.
Save ismailkarsli/dd71cd5ebb3b1a611ddb56b1bdc238c5 to your computer and use it in GitHub Desktop.
Automatically prune docker system when disk limit exceeds
#!/bin/sh
ROOT_FS_USAGE=$(df -H / | grep -vE 'Filesystem' | awk '{ print $5}' | cut -d'%' -f1)
DISK_LIMIT=${DISK_LIMIT:-75}
if [ "$ROOT_FS_USAGE" -ge "$DISK_LIMIT" ]; then
echo "Cleaning up docker images"
docker system prune -af --filter="until=1h"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment