Skip to content

Instantly share code, notes, and snippets.

@sebald
Last active August 19, 2016 13:53
Show Gist options
  • Save sebald/8b18cda0c69ce3acff9731ff3ea6ea65 to your computer and use it in GitHub Desktop.
Save sebald/8b18cda0c69ce3acff9731ff3ea6ea65 to your computer and use it in GitHub Desktop.
# Remove all stopped containers.
function docker-stop () {
if [[ $(docker ps -a -q) ]]; then
docker rm $(docker ps -a -q)
echo -e "\xf0\x9f\x93\xa6 ➡ \xf0\x9f\x92\xa5 All stoped containers removed!"
else
echo -e "\xf0\x9f\x91\x8c Nothing to stop!"
fi
}
# Remove all "<none>" images.
function docker-none () {
if [[ $(docker images | grep "^<none>" | awk "{print $3}") ]]; then
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
echo -e "\xf0\x9f\x96\xbc ➡ \xf0\x9f\x92\xa5 Cleaned <none> images!"
else
echo -e "\xf0\x9f\x91\x8c Nothing to clean!"
fi
}
# Kill all running containers.
function docker-killall () {
if [[ $(docker ps -q) ]]; then
docker kill $(docker ps -q)
echo -e "\xe2\x98\xa0 All active containers killed!"
else
echo -e "\xf0\x9f\x91\x8c Nothing to kill!"
fi
}
# Clean/remove all the things.
function docker-clean () {
docker-stop
docker-none
echo -e "\xf0\x9f\x90\x8b \xf0\x9f\x90\x8b \xf0\x9f\x90\x8b Done! \xf0\x9f\x90\x8b \xf0\x9f\x90\x8b \xf0\x9f\x90\x8b"
}
# Stop all containers and then remove stuff...
function docker-kc () {
docker-killall
docker-clean
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment