How to stop all running Docker containers

If you like me use Docker for mostly everything you may find yourself accidentally leaving your containers running after you are done with them.

Errors such as this may occor when your containers are left running:

docker start php

Error: Cannot start container php: port has already been allocated

To alleviate this issue you can try to stop all running containers. There is no single command to do this in Docker yet.

Instead you may stop the containers by piping the running instance IDs to docker stop:

docker ps -q | xargs docker stop

I find myself using this every once in a while so I made an alias out of it (dsac is short for Docker stop all containers):

alias dsac="docker ps -q | xargs docker stop"