-
-
Save dcchambers/0b3d0f927f27bf8339e3367b8b734dae to your computer and use it in GitHub Desktop.
Docker Nuke (Safely) π³π£- Clean up your Docker environment in a (sort of) safe way!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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-safely exists to do one thing; clean up your Docker environment. It's not called docker-carefully-and-nicely-spritz-up. Be careful!" | |
echo | |
read -p "Nuke now? [y/N] " -n 1 -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo | |
read -p "Would you like to stop all containers? [y/N] " -n 1 -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo "Stoping all containers" | |
docker stop $(docker ps -a -q) | |
fi | |
echo | |
read -p "Would you like to delete all containers? [y/N] " -n 1 -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo "Deleting all containers" | |
docker rm $(docker ps -a -q) | |
fi | |
echo | |
read -p "Would you like to delete all images? [y/N] " -n 1 -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo "Deleting all images" | |
docker rmi $(docker images -q) | |
fi | |
echo | |
read -p "Would you like to delete all volumes? [y/N] " -n 1 -r | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo "Deleting all volumes" | |
rm -rf /var/lib/docker/volumes/* | |
rm -rf /var/lib/docker/vfs/dir/* | |
fi | |
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