DEV Community

Wriju's Blog
Wriju's Blog

Posted on

1 1

How to delete all Docker containers using a single Command

There may be a many containers either running or exited in your development machine. You need to clean them up in a regular basis.

To see the list of docker container running locally,

docker ps
Enter fullscreen mode Exit fullscreen mode

But it does not show the excited containers. To see them all use -a

docker ps -a
Enter fullscreen mode Exit fullscreen mode

Finally to delete you need to pass either the id or the name of each container. Wouldn't it be nice to delete them in a loop (its the concept here but we are not using it)? YES indeed it would be. To get only the ids of all the containers we can use -q switch.

So to get the list of only ids for all the containers we can use,

docker ps -a -q 
Enter fullscreen mode Exit fullscreen mode

or

docker ps -aq
Enter fullscreen mode Exit fullscreen mode

To delete we use

docker rm container_id
Enter fullscreen mode Exit fullscreen mode

If we want to loop (again not actual loop but a concept) through all

docker rm $(docker ps -aq)
Enter fullscreen mode Exit fullscreen mode

That's it - your magic command to delete all the running and exited containers in your machine.

This works in Linux (not in Windows).

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (1)

Collapse
 
wrijugh profile image
Wriju's Blog •

I liked your explanation. Learned few things. Many thanks.

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more