Skip to content

Instantly share code, notes, and snippets.

@rafaelaazevedo
Last active August 23, 2023 13:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rafaelaazevedo/bec6cf339888bbac60336d01193ae923 to your computer and use it in GitHub Desktop.
Save rafaelaazevedo/bec6cf339888bbac60336d01193ae923 to your computer and use it in GitHub Desktop.
Clean all docker images/containers/volumes script
#!/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