Remove all Docker Containers

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

Recently I've been learning about Docker and Containers. In the process of learning this resulted in creating a bunch of containers and then shutting them all down one-by-one. And if I had 30 containers, this could take quite awhile.

Instead of wasting my time shutting them down and removing them one by one, I needed a way to stop all the containers and then remove them. If you are in need of the same functionality, simply run the following 2 commands:

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

Now, if you were to run docker ps -a you will no longer see any more containers and you can start off with a clean slate :)

BETA Snippet explanation automatically generated by OpenAI:

Here is what the above code is doing:
1. It first stops all the running containers and then removes them.
2. It then removes all the stopped containers.
3. Finally it removes all the dangling images.









Snippet By Dev Dojo

·

Created June 12th, 2021

·

Report Snippet