Using the CLI
The quick way to (manually) know if the manager changed is through the CLI:
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
46aqrk4e473hjbt745z53cr3t node-5 Ready Active Reachable
61pi3d91s0w3b90ijw3deeb2q node-4 Ready Active Reachable
a5b2m3oghd48m8eu391pefq5u node-3 Ready Active
e7p8btxeu3ioshyuj6lxiv6g0 node-2 Ready Active
ehkv3bcimagdese79dn78otj5 * node-1 Ready Active Leader
You can find out which Manager is the current Leader under the MANAGER STATUS
column.
You can also check individually on each node formatting with the Leader
field, for example:
$ docker node inspect <id-node> --format "{{ .ManagerStatus.Leader }}"
true
Using the Docker Remote API
You can also check which one of the manager is the leader programmatically. The docker remote API exposes a Nodes API endpoint
that you can use to list nodes.
You can provide a filter as a parameter which takes the key=value
form.
You can use that filter to list manager nodes only (with role=manager
), then you can parse and filter the JSON output to keep the node whose Leader
field is set at true
(under ManagerStatus
).
Unfortunately there is no leader
filter (yet) but I assume that this could be a valid enhancement to propose on the swarmkit issue tracker.
There are no events stream on docker swarm mode yet (this is tracked by this issue on the swarmkit repository). I imagine that in the future, an event will trigger on Leader switch and you will be dynamically notified of the new leader if you are listening to these events (for example if you have a special setup and want to dynamically update entries in consul, nginx or Interlock).