Over time, Docker can accumulate unused resources like containers, images, volumes, and networks. These unused resources consume disk space and can make your Docker environment less efficient. To keep your system clean and free up disk space, it's a good practice to regularly prune these resources using Docker's built-in commands.
Here are some useful commands for resource pruning:
- Prune Unused Containers:
docker container prune
- Prune Unused Images:
docker image prune
- Prune Unused Volumes:
docker volume prune
- Prune Unused Networks:
docker network prune
- Prune All Unused Resources (Containers, Images, Volumes, Networks):
docker system prune
Please exercise caution when using these commands, especially the docker system prune
command, as it will remove all unused resources, and there's no way to recover them once they are pruned. It's a good practice to periodically run these commands, but be mindful of their potential impact on your Docker environment.
You can also automate resource pruning by setting up a scheduled job or script to run these commands regularly. This helps maintain a clean and efficient Docker environment and can prevent unexpected resource-related issues in the future.
Top comments (6)
Started to learn Docker, and great to know that !
I'm also learning docker.
I always recommend using the --help command to check more information.
e.g.: docker container --help
If you prefer, you can search by keywords.
e.g.:
docker container | grep stop
anything involving the word "stop" will return.
Thanks 👍
I use this all the time. Great for saving space on your Docker hosts.
Tks
docker system prune will not remove volumes. If you want it to do so, make sure to add the --volumes flag.