Skip to main content

Cleaning up in Docker - Part 2

·199 words·1 min
system-administration tech containers docker linux sysadmin technology
James Pettigrove
Author
James Pettigrove
Cloud Engineer with a focus on Microsoft Azure
Table of Contents

Previously we have covered what to do if you made a real mess of things in Docker and just want to purge all your containers, volumes and images from your host system. What happens though if you have active running containers and don’t want to bring them down but still want to do some spring cleaning? Well, Docker has come a long way in recent times and now there happens to be a non destructive way to go about it.

Remove all non-running containers
#

docker containers prune

Remove all not in use volumes
#

docker volume prune

Remove all not in use images
#

docker image prune

Are you sensing a theme yet? Although we touched on the prune command previously, it was in conjunction with the destructive -f , force switch. Now, you could pound out all the above commands into your shell one by one but if you want a quick and easy clean of all elements in one foul swoop?

Remove all containers, volumes, images and networks not in use
#

docker system prune

Compare the pair:

Definitely much shorter, sweeter and a whole lot more (IT) lazier. Just the way a SysAdmin likes it.

Related

Let's get certified!
·393 words·2 mins
system-administration tech certification cloud containers docker gcp google-cloud k8s kubernetes learning lfcs linux sysadmin technology
It’s been a long time between drinks for certifications that I have achieved personally.
Keeping your Pi-Hole container fresh with Cron
·396 words·2 mins
system-administration tech containers cron docker linux pihole raspberry-pi raspbian sysadmin technology
In our previous entry, we unleashed the awesome that is Pi-Hole inside a Docker container to make all the devices in our network ad-free when browsing the internet.
Cleaning up in Docker - Part 1
·93 words·1 min
system-administration tech containers debian docker iot linux raspberry-pi raspbian technology
So you have read how to get Docker on your Raspberry Pi, had a play around and now you have containers, images and volumes running wild.