Skip to content

Instantly share code, notes, and snippets.

@erpalma
Created June 5, 2018 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erpalma/afdb15b18e91e5e73ff2afa61cfd395b to your computer and use it in GitHub Desktop.
Save erpalma/afdb15b18e91e5e73ff2afa61cfd395b to your computer and use it in GitHub Desktop.
Cleaning up some docker mess
#!/bin/bash
echo "Cleaning unused docker files..."
docker ps --all --quiet --filter="status=exited" | xargs --no-run-if-empty docker rm --volumes
IMAGES=`docker images | awk '/^<none>/ { print $3 }'`
if [[ $IMAGES ]]; then
echo -e "\nCleaning untagged images..."
docker rmi --force $IMAGES
fi
VOLUMES=`docker volume ls --quiet --filter="dangling=true"`
if [[ $VOLUMES ]]; then
echo -e "\nCleaning volumes..."
docker volume rm $VOLUMES
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment