DEV Community

Bevan
Bevan

Posted on • Originally published at intenseagile.com

1 2

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more