Get rid of unwanted docker containers

If you use docker as a development environment, you are bound to run into creating a bunch of containers that you don’t want anymore. Luckily, there is relatively simple way to get rid of them

Bash
docker rm $(docker ps -q -f status=exited)

This will clear all containers that have exited. Here is a more complicated and yet more flexible example taken from stack overflow

Bash
docker ps --filter "status=exited" | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm

If you really want to clean things up, you can try docker system prune or docker container prune

Leave a Reply

I’m David

Welcome to my little corner of the internet that I dedicate to programming. I’m a principal software engineer at Fynix Consulting and strive to always be learning new things. I love to code and I love to write about coding!

Let’s connect

Discover more from David Boothe's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading