DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

Bevan
Bevan

Posted on • Originally published at intenseagile.com

Quick one liner to purge docker containers and images

Does what it says on the tin. I'm using fish so my one liner looks like this:

docker rm (docker ps -a -q) && docker rmi -f (docker image ls -q)

If you're running a more standard shell like bash, you'll probably need some $s in there:

docker rm $(docker ps -a -q) && docker rmi -f $(docker image ls -q)

It's pretty simple - docker rm removes containers. It accepts a list of container Ids. docker ps -a -q lists all containers in quiet mode - so just the container Ids.

The logic is the same for removing images - I've thrown in the f force flag for good measure, and I've used && to concatenate two commands onto one line.

This will error out if you have no containers. Be warned.

Top comments (0)

๐Ÿ‘‹ Hey, my name is Noah and Iโ€™m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, Iโ€™d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: