Search code examples
dockerdocker-swarmraft

In Docker swarm mode, is there a way to get managers' information from workers?


In docker swarm mode I can run docker node ls to list swarm nodes but it does not work on worker nodes. I need a similar function. I know worker nodes does not have a strong consistent view of the cluster, but there should be a way to get current leader or reachable leader.

So is there a way to get current leader/manager on worker node on docker swarm mode 1.12.1?


Solution

  • The docs and the error message from a worker node mention that you have to be on a manager node to execute swarm commands or view cluster state:

    Error message from a worker node: "This node is not a swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager."

    After further thought: One way you could crack this nut is to use an external key/value store like etcd or any other key/value store that Swarm supports and store the elected node there so that it can be queried by all the nodes. You can see examples of that in the Shipyard Docker management / UI project: http://shipyard-project.com/

    Another simple way would be to run a redis service on the cluster and another service to announce the elected leader. This announcement service would have a constraint to only run on the manager node(s): --constraint node.role == manager