sajad torkamani

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