Skip to content

Instantly share code, notes, and snippets.

@barthap
Created December 4, 2021 09:50
Show Gist options
  • Save barthap/99308bcd22ff09f82bb75da9b92c0927 to your computer and use it in GitHub Desktop.
Save barthap/99308bcd22ff09f82bb75da9b92c0927 to your computer and use it in GitHub Desktop.
Remove dangling Docker images. Useful when you often use `docker compose pull` and your disk gets clogged with old images.
#!/bin/bash
set -euo pipefail
echo "These images are gonna be removed:"
docker images -f "dangling=true"
echo
read -p "Do you want to continue? [yN]" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Removing dangling images..."
docker rmi $(docker images -f "dangling=true" -q)
echo "All done"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment