Sometimes an issue on one of your servers may interrupt your Docker based development and stop all the containers that you haven’t fully configured to be auto-started just yet. In such cases, it will be useful for you to know how to find stopped containers and restart them all using a single command.
List Stopped Containers in Docker
Using the filtering functionality of the docker ps command, we can quickly get all the necessary information for the stopped containers:
Since we want to restart of these containers, we’ll probably need to pass their docker container IDs to another command, like docker start.
Hence the command above should be run with the -q parameter, which skips all the non-essential info and only returns the list of docker containers:
Restart all the Stopped Containers in Docker
Now all we have left to do is pass the above command to the docker start, like shown below. One by one, all the container IDs will appear as Docker restarts them:
Sure enough, when we do docker ps now, we should see these containers:
I can see the 014a746dbb9d container, but the other one is not running. Want to know why? It’s because this was a Hello, world Docker container – it’s not mean to stay running in background. Instead, it shows Hello, world and exits. It’s usually run like this: