Restart all docker containers

Restart Docker

If you want to restart single container, you could use the below command:

sudo docker restart <container id>

There are many use cases where you want to restart multiple docker containers. Doing it one by one may be daunting. The below technic uses the output of one docker command and feeds it to the other.

Restart all running containers
sudo docker restart $(sudo docker ps -q)
// -q : quite output
Restart all containers matching certain names
sudo docker restart $(sudo docker ps -q -f name=redis*)

// -q : quite output
// -f : filter output
Delayed restart of all containers
sudo docker restart $(sudo docker ps -q -f name=redis*) -t 5
// -t : Seconds to wait for stop before killing the container