Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Artem-Schander/86f058860e1be61fd342237b93818f8d to your computer and use it in GitHub Desktop.
Save Artem-Schander/86f058860e1be61fd342237b93818f8d to your computer and use it in GitHub Desktop.
Docker Swarm automatically rebalance when new worker node joins
FILE=/tmp/worker.nodes
touch ${FILE} || exit
for node in `docker node ls --filter role=worker -q`; do
if grep -Fxq "${node}" ${FILE}
then
echo "This node ${node} already exists"
else
echo "This node ${node} joined recently, so rebalance"
for service in `docker service ls -q`; do
docker service update --with-registry-auth --detach=true --force ${service}
done
fi
done
docker node ls --filter role=worker -q > ${FILE}
@Artem-Schander
Copy link
Author

Artem-Schander commented Apr 19, 2018

Or docker service ls -q > dkr_svcs && for i in cat dkr_svcs; do docker service update "$i" --detach=false --force ; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment