Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (2.3k points)

How can you remove all the containers; stopped/running, both? I think its a lot easier to sometimes just start from scratch. I find it difficult to remove all the containers one by one using the docker rm command as docker won't let me.

1 Answer

0 votes
by (6.9k points)

You can use the below command to stop all containers running: 

$ docker stop $(docker ps -a -q)

then you can remove all of the containers using this command:

$ docker rm $(docker ps -a -q)

If you want to remove all of the containers  without stopping them, you can use th -f flag:

$ docker rm -f $(docker ps -a -q)

Hope this helped :)

Get trained by Docker veterans in online docker training course! 

Browse Categories