Created
January 13, 2021 22:51
-
-
Save Santhin/bc976d32a41967d490d852f72367bb28 to your computer and use it in GitHub Desktop.
docker cleaner taken from stack/github
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 | |
# Stop and remove all containers | |
echo "Removing containers :" | |
if [ -n "$(docker container ls -aq)" ]; then | |
docker container stop $(docker container ls -aq); | |
docker container rm $(docker container ls -aq); | |
fi; | |
# Remove all images | |
echo "Removing images :" | |
if [ -n "$(docker images -aq)" ]; then | |
docker rmi -f $(docker images -aq); | |
fi; | |
# Remove all volumes | |
echo "Removing volumes :" | |
if [ -n "$(docker volume ls -q)" ]; then | |
docker volume rm $(docker volume ls -q); | |
fi; | |
# Remove all networks | |
echo "Removing networks :" | |
# Skip default networks : bridge, host, none | |
if [ -n "$(docker network ls | awk '{print $1" "$2}' | grep -v 'ID\|bridge\|host\|none' | awk '{print $1}')" ]; then | |
docker network rm $(docker network ls | awk '{print $1" "$2}' | grep -v 'ID\|bridge\|host\|none' | awk '{print $1}'); | |
fi; | |
# Your installation should now be all fresh and clean. | |
# The following commands should not output any items: | |
# docker ps -a | |
# docker images -a | |
# docker volume ls | |
# The following command show only show the default networks: | |
# docker network ls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment