Do you use docker for your local development environments? Do you use it for multiple projects. You may have seen an error like this:
Cannot start service db: drive failed programming external connectivity on endpoint…
This message appears because you have an existing docker container running that is using the port your new container is attempting to use (in my case, this is almost always port 3306 for MySQL containers).
But there is a really easy way to stop all running containers, even if you don’t know which folder you started it from:
docker stop $(docker ps -aq)
How does this work?
Let’s break it down:
$()allows us to embed the result of one command as the argument passed to the
psis the docker command to list containers
-ais the flag to list all containers
-qenables “quiet” mode which outputs only the container IDs, which is the argument that the
docker stopcommands is expecting.