One-liner to remove all Docker containers
11 March 2022 (Updated 13 May 2022)
When working with Docker, I usually end up with a bunch of running or stopped containers. Removing each one using docker rm <id> is tedious. Here’s a one liner to remove them all, including the ones that are stopped.
docker rm -f $(docker ps -aq)
-a: Show all containers (even those that are stopped)-q: Only display numeric IDs
docker ps -aq will give you the list of all the container IDs. Once you have the container IDs, you pass it to docker rm -f which will remove them all, even if they are running (thanks to -f).
Tagged:
Docker
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment