Docker deep clean with one command
Currently I’ve had to rebuild our development environment many times, and a lot of containers, images, volumes, and networks keep taking up disk space. I wanted an easy way to remove all the extra stuff with one command.
docker system prune -a --volumes -f
What it does
docker system prune- Removes unused Docker data:- stopped containers
- unused networks
- dangling images (images without a tag)
-a/--all- Also removes all unused images, not only dangling ones.--volumes- Removes unused volumes that are not used by any container.-f/--force- Runs the command without asking for confirmation.
Use with extreme caution
This command is destructive. It will permanently delete:
- all stopped containers
- all unused networks
- all unused images (not only dangling ones)
- all unused volumes
Once removed, they cannot be recovered. If you have important data in a volume, make sure to back it up first.