DEV Community

Discussion on: How to clean up your Docker environment

Collapse
 
cyberjack profile image
CyberJack

Nice function, but did you know Docker has it's own clean up mechanism? It's called "docker system prune" and it's available since api version 1.25. It can be used to remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.

By default it will remove all stopped containers, all networks not used by at least one container, all dangling images and all build cache.

When adding the -a and --volumes parameters it will remove all stopped containers, all networks not used by at least one container, all volumes not used by at least one container, all images without at least one container associated to them and all build cache.

Collapse
 
deepu105 profile image
Deepu K Sasidharan

Wow cool. I didn't know that and when I was originally writing this function few months ago it never came up in any of the resources I found. Cool. I'll try it out.

Collapse
 
deepu105 profile image
Deepu K Sasidharan

Well talk about making the entire post irrelevant 😉

Thread Thread
 
cyberjack profile image
CyberJack • Edited

I don't think its irrelevant at all. The system prune command only works when you want to clean your entire docker setup. All these commands give you more control when you want to clean only certain parts of your docker setup.