Skip to content

Instantly share code, notes, and snippets.

@n3r0-ch
Last active August 23, 2019 16:44
Show Gist options
  • Save n3r0-ch/30c628813b67190d309d to your computer and use it in GitHub Desktop.
Save n3r0-ch/30c628813b67190d309d to your computer and use it in GitHub Desktop.
docker-nuke exists to do one thing; clean up your Docker environment. It's not called docker-carefully-and-nicely-spritz-up. Be carefully!
#!/bin/bash
#Check if user is root
if [ $UID != 0 ]; then
echo "You need to be root to use this script."
exit 1
fi
echo "docker-nuke exists to do one thing; clean up your Docker environment. It's not called docker-carefully-and-nicely-spritz-up. Be carefully!"
echo
read -p "Nuke now? [y/N] " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
echo "Stop all containers"
docker stop $(docker ps -a -q)
echo
echo "Delete all containers"
docker rm $(docker ps -a -q)
echo
echo "Delete all images"
docker rmi $(docker images -q)
echo
echo "Delete all volumes"
rm -rf /var/lib/docker/volumes/*
rm -rf /var/lib/docker/vfs/dir/*
echo
echo
echo "Finished nuking"
else
echo "Cancelled"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment