Command for restarting all running docker containers?

DockerDocker Machine

Docker Problem Overview


How to restart all running docker containers? Mainly looking for a shortcut instead of doing

> docker restart containerid1 containerid2

Docker Solutions


Solution 1 - Docker

Just run

docker restart $(docker ps -q)

Update

For restarting ALL (stopped and running) containers use docker restart $(docker ps -a -q) as in answer lower.

Solution 2 - Docker

For me its now :

docker restart $(docker ps -a -q)

Solution 3 - Docker

If you have docker-compose, all you need to do is:

docker-compose restart 

And you get nice print out of the container's name along with its status of the restart (done/error)

Here is the official guide for installing: https://docs.docker.com/compose/install/

Solution 4 - Docker

To start only stopped containers:

docker start $(docker ps -a -q -f status=exited)

(On windows it works in Powershell).

Solution 5 - Docker

To start all the containers:

  docker restart $(docker ps -a -q)

Use sudo if you don't have permission to perform this:

sudo docker restart $(sudo docker ps -a -q)

Solution 6 - Docker

To start multiple containers with the only particular container ids $ docker restart container-id1 container-id2 container-id3 ...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRanjith'sView Question on Stackoverflow
Solution 1 - DockerAndrey RomashinView Answer on Stackoverflow
Solution 2 - DockerbohrView Answer on Stackoverflow
Solution 3 - DockerbenjaminzView Answer on Stackoverflow
Solution 4 - DockerCepr0View Answer on Stackoverflow
Solution 5 - DockerHitesh KumarView Answer on Stackoverflow
Solution 6 - Dockernaveen chanderView Answer on Stackoverflow