
Docker is a widely used containerization platform for building, running, and distributing applications. As you develop and deploy containers over time, Docker can accumulate unused objects like stopped containers, dangling images, unused volumes, and networks. These leftover resources consume disk space and may degrade system performance if not cleaned up.
This article explains how to use the docker prune command family to safely remove unused Docker resources. You’ll learn the differences between docker prune and manual deletion, how to use each prune variant effectively, and best practices to prevent accidental data loss during cleanup.
docker prune?The docker prune command family helps you remove unused Docker resources like stopped containers, dangling images, unused volumes, networks, and build cache, all in one go. It's faster and less manual than using docker rm or docker rmi.
Use docker rm when you need precision. Use docker prune when you want to clean everything efficiently.
docker pruneMost docker prune commands support the following options:
Use filters to avoid removing recently created resources during cleanup.
docker system pruneUse this command to remove all unused containers, networks, dangling images, and build cache.
Clean up all unused Docker resources interactively.
Clean up all unused resources without confirmation.
Clean up unused resources older than 48 hours.
docker container pruneUse this command to remove only stopped containers. Running containers are not affected.
Remove all stopped containers.
Remove all stopped containers without confirmation.
Remove stopped containers older than 24 hours.
docker image pruneThis command removes unused Docker images. By default, it only removes dangling images — images that are untagged and not referenced by any containers.
Remove all dangling images.
Remove all unused images (not just dangling ones).
Remove unused images older than 72 hours.
docker volume pruneThis command removes volumes that are not referenced by any containers. Active or attached volumes are not affected.
Remove all unused volumes interactively.
Remove all unused volumes without confirmation.
Volume data is not recoverable after deletion. Always verify which volumes are in use before pruning.
docker network pruneUse this command to remove Docker networks that are not connected to any running or stopped containers.
Remove all unused networks interactively.
Remove all unused networks without confirmation.
docker-composedocker builder pruneThis command removes the build cache created during image builds. By default, it only removes dangling (unused) cache layers.
Remove dangling build cache interactively.
Remove all unused build cache without confirmation.
In this article, you learned how to clean up unused Docker resources using the docker prune command family. You explored how to remove stopped containers, dangling images, unused volumes and networks, and build cache safely and efficiently. These commands help maintain a clean development environment and reduce disk usage.
0 Comments
Be the first to comment and share your perspective with the community.