X

Docker Restart All Containers (but faster)

Whenever I have to restart my docker host, an Ubuntu VM, I always seem to have a few containers that don’t start back quite right. I’ve googled “docker restart all containers” an embarrassing number of times to get to this Stack Overflow post, and these days Google’s AI summary even gives the same quick answer, which is:

docker restart $(docker ps -q)

But that starts each container one after another, and it can take quite a while. Today I decided it was worth speeding up the process and was happy to find this alternative:

docker ps -q | xargs -n 1 -P 4 docker restart

This gets all containers and runs individual restart commands in parallel. Adjust the -P parameter to how many you want to restart at once (that’ll depend on the number of containers you have compared to the power of your system). A 4x (or more) time savings on restarting everything is great!

Categories: Uncategorized
Related Post