DEV Community

Cover image for Prune Unused Resources in Docker
Keyur Ramoliya
Keyur Ramoliya

Posted on

Prune Unused Resources in Docker

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
Enter fullscreen mode Exit fullscreen mode
  • Prune Unused Images:
  docker image prune
Enter fullscreen mode Exit fullscreen mode
  • Prune Unused Volumes:
  docker volume prune
Enter fullscreen mode Exit fullscreen mode
  • Prune Unused Networks:
  docker network prune
Enter fullscreen mode Exit fullscreen mode
  • Prune All Unused Resources (Containers, Images, Volumes, Networks):
  docker system prune
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
thomasbnt profile image
Thomas Bnt ☕

Started to learn Docker, and great to know that !

Collapse
 
spldr profile image
Felipe

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.

Collapse
 
thomasbnt profile image
Thomas Bnt ☕

Thanks 👍

Collapse
 
noted profile image
Jeremy

I use this all the time. Great for saving space on your Docker hosts.

Collapse
 
hectorlaris profile image
Héctor Serrano

Tks

Collapse
 
metalarend profile image
Bart Reunes

docker system prune will not remove volumes. If you want it to do so, make sure to add the --volumes flag.