Docker, a robust tool for containerizing applications, efficiently manages resources but can consume considerable disk space. Employ these commands to tidy up and optimize your Docker environment:
1. Cleanup Docker Images
Remove all unused Docker images:
docker image prune -a
For solely removing dangling images (those unassociated with any containers):
docker image prune
Filter images by age for removal (e.g., images older than 30 days):
docker image prune -a --filter "until=720h"
2. Cleanup Docker Containers
Remove all stopped containers:
docker container prune
Forcefully remove all containers (stopped and running):
docker rm -f $(docker ps -a -q)
3. Cleanup Docker Volumes
Remove all unused volumes:
docker volume prune
Filter volumes, eliminating those unassociated with containers:
docker volume prune --filter "dangling=true"
4. Docker Cleanup Everything
To comprehensively clean up all unused images, stopped containers, and volumes:
docker system prune -a --volumes
Note: Exercise caution when using system-wide cleanup commands as they remove all unused components.
Utilize these Docker cleanup commands judiciously to reclaim disk space and maintain a streamlined development environment.