Posts

Showing posts from May, 2018

Managing Docker Restart Policy On a Set of Hosts

Image
Then you have been moving containers back and forth through the hosts (no Kubernetes yet), and each host has some containers running and some stopped. When you need to restart the host (or even the docker service), all containers start running, even the ones you already moved to another host. It's common to run a container and set the Restart Policy to Always, so that the container is started automatically once docker determines it is stopped (possibly after a restart). And its common to forget resseting this setting once the container is moved to another host. So StackOverflow comes to the rescue (thanks OscarAkaElvis) and provides a nice script to loop through all containers in a host and shows Restart Policy for each: #!/usr/bin/env bash #Script to check the restart policy of the containers readarray -t CONTAINERS < < ( docker ps -a | grep -v NAMES | awk '{print $NF}' ) for item in "${CONTAINERS[@]}" ; do #Hard-Bash way #dat