Skip to content

Instantly share code, notes, and snippets.

@monorkin
Last active December 1, 2016 12:53
Show Gist options
  • Save monorkin/d2c801d193ce48224ae052b49ba60856 to your computer and use it in GitHub Desktop.
Save monorkin/d2c801d193ce48224ae052b49ba60856 to your computer and use it in GitHub Desktop.
Script for cleaning garbage docker files
# Remove stopped images
echo "Removing unused containers..."
if [[ -z $(docker ps -a -q) ]]
then
echo "No unused containers found."
else
docker rm $(docker ps -a -q)
fi
# Remove dangling volumes
echo "Removing dangling volumes..."
if [[ -z $(docker volume ls -qf dangling=true) ]]
then
echo "No dangling volumes found."
else
docker volume rm $(docker volume ls -qf dangling=true)
fi
# Remove dangling images
echo "Removing dangling images..."
if [[ -z $(docker images -a -f "dangling=true" -q) ]]
then
echo "No dangling images found."
else
docker rmi $(docker images -a -f "dangling=true" -q)
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment