Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.