Docker cleanup
Docker is an incredibly powerful tool for containerizing applications, but it can quickly consume a significant amount of disk space on your machine.
Cleanup Docker images
To remove all unused Docker images, run
docker image prune -a
If you want to remove only dangling images (i.e., images that aren't associated with any containers), simply omit the -a flag:
docker image prune
Additionally, you can filter the images you want to remove by adding the --filter flag. For instance, to remove images older than 30 days, run:
docker image prune -a --filter "until=720h"
Cleanup Docker containers
To remove all stopped containers, run
docker container prune
If you want to remove all containers, including the running ones, you can use the docker rm command with the -f flag:
docker rm -f $(docker ps -a -q)
Cleanup Docker volumes
To remove all unused volumes, run
docker volume prune
You can also filter the volumes you want to remove by using the --filter flag. For example, to remove volumes that are not associated with any containers, run
docker volume prune --filter "dangling=true"
Docker cleanup everything
If you want to clean up everything, including unused images, stopped containers, and unused volumes
docker system prune -a --volumes