Skip to content

Instantly share code, notes, and snippets.

@tebeka
Last active August 14, 2018 03:34
Show Gist options
  • Save tebeka/ab6c480ea736d9a16655761e82d48eea to your computer and use it in GitHub Desktop.
Save tebeka/ab6c480ea736d9a16655761e82d48eea to your computer and use it in GitHub Desktop.
Cleanup Docker
#!/bin/bash
# Cleanup docker containers and volumes
case $1 in
-h | --help ) echo "usage: $(basename $0)"; exit;;
esac
if [ $# -ne 0 ]; then
1>&2 echo "error: wrong number of arguments"
exit 1
fi
docker ps -a --filter status=exited --format {{.ID}} | xargs -i docker rm {}
docker images -f dangling=true -q | xargs -i docker rmi {}
docker volume ls -q -f dangling=true | xargs -i docker volume rm {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment