Skip to content

Instantly share code, notes, and snippets.

@ourway
Created January 1, 2023 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ourway/132f3b7cd8d43b3819b7c80d7eb78eaf to your computer and use it in GitHub Desktop.
Save ourway/132f3b7cd8d43b3819b7c80d7eb78eaf to your computer and use it in GitHub Desktop.
#!/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