One-liners: Stopping all your docker containers

Let’s say you have multiple docker projects on your laptop and in the course of a day you bounce around between them. It’s easy to forget which ones have been shut down and which haven’t. If you’re using docker-compose this could mean several containers are running and eating your battery. Here’s a simple one-liner to shut them all down.

docker ps -q | xargs docker stop