Stop and remove all docker containers

Stop all the containers

docker stop $(docker ps -a -q)

Remove all the containers

docker rm $(docker ps -a -q)

Find more command here


Docker introduced new namespaces and commands which everyone should finally learn and not stick to the old habits. Here is the documentation, and here are some examples:

Deleting no longer needed containers (stopped)

docker container prune

Deleting no longer needed images

which means, that it only deletes images, which are not tagged and are not pointed on by "latest" - so no real images you can regularly use are deleted

docker image prune

Delete all volumes, which are not used by any existing container

( even stopped containers do claim volumes ). This usually cleans up dangling anon-volumes of containers have been deleted long time ago. It should never delete named volumes since the containers of those should exists / be running. Be careful, ensure your stack at least is running before going with this one

docker volume prune

Same for unused networks

docker network prune

And finally, if you want to get rid if all the trash - to ensure nothing happens to your production, be sure all stacks are running and then run

docker system prune