By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Cleaning up unused Docker resources frees up disk space and improves system performance. docker system prune.
docker system df
docker system prune -a
docker system prune -a --volumes
docker images -a
docker image prune -a
docker image prune -a --force
docker ps -a
docker container prune
docker volume ls
docker volume prune
docker network ls
docker network prune
Purpose: Remove unused Docker images.Command: docker image prune -a Flags: -a removes all unused images, --force forces the deletion.
-a
--force
Purpose: Remove stopped Docker containers.Command: docker container prune Flags: None, but be cautious as this deletes all stopped containers.
Purpose: Remove unused Docker volumes.Command: docker volume prune Flags: None, but be cautious as this deletes all unused volumes.
Error message or symptom: Unable to prune a volume.Why it happens: The volume is still in use by a container.One-line fix: docker container stop <container_name> && docker volume prune
docker container stop <container_name> && docker volume prune
Error message or symptom: Unable to prune a network.Why it happens: The network is still in use by a container.One-line fix: docker network disconnect <network_name> <container_name> && docker network prune
docker network disconnect <network_name> <container_name> && docker network prune
Error message or symptom: Unable to prune an image.Why it happens: The image is still in use by a container.One-line fix: docker container stop <container_name> && docker image prune -a
docker container stop <container_name> && docker image prune -a
Situation: You want to free up disk space.Command to run: docker images -a Correct response: A list of unused images with their IDs and sizes.
Situation: You want to remove stopped containers.Command to run: docker ps -a Correct response: A list of stopped containers with their IDs and names.
Situation: You want to remove unused volumes.Command to run: docker volume ls Correct response: A list of unused volumes with their names and sizes.
• -a flag: removes all unused resources.• --volumes flag: includes volumes in the prune operation.• --force flag: forces the deletion of resources.• docker system df: displays disk usage statistics.• docker system prune -a: removes all unused resources.• docker image prune -a: removes all unused images.• docker container prune: removes all stopped containers.• docker volume prune: removes all unused volumes.• docker network prune: removes all unused networks.• ⚠️ Be cautious when using docker system prune -a, docker image prune -a, docker container prune, and docker volume prune as they delete resources permanently.
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.