Last active
August 23, 2023 13:51
-
-
Save rafaelaazevedo/bec6cf339888bbac60336d01193ae923 to your computer and use it in GitHub Desktop.
Clean all docker images/containers/volumes script
This file contains hidden or 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 | |
# Kill all running containers. | |
docker kill $(docker ps -q) | |
# Delete all stopped containers. | |
printf "\n>>> Deleting stopped containers\n\n" && docker rm $(docker ps -a -q) | |
# Delete all untagged images. | |
printf "\n>>> Deleting untagged images\n\n" && docker rmi $(docker images -q -f dangling=true) | |
# Delete all images. | |
printf "\n>>> Deleting untagged images\n\n" && docker rmi $(docker images -q) | |
# Delete all volumes. | |
printf "\n>>> Deleting volumes\n\n" && docker volume rm $(docker volume ls -q) | |
# Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes. | |
printf "\n>>> Deleting unused containers, networks, images and volumes\n\n" && docker system prune -a --volumes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment