欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Error response from daemon: rpc error: code = Unknown desc = The swarm does not have a leader. It‘s

程序员文章站 2022-03-12 12:27:37
...

今天在本机虚拟机用docker stack起eureka的service发现有以下报错:

docker stack depoly -c <ymlname> <servicename>
Error response from daemon: rpc error: code = Unknown desc = The swarm does not have a leader. It's possible that too few managers are online. Make sure more than half of the managers are online.

【原因】这是由于集群中的manager节点出现异常导致的问题
【我的环境】一共三台节点,其中练习手动添加manager节点的时候,添加了两个manager节点,今天只启动了一个manager节点
于是想看一下节点情况,结果又出现了以下报错

docker node ls
Error response from daemon: rpc error: code = Unknown desc = The swarm does not have a leader. It's possible that too few managers are online. Make sure more than half of the managers are online.

解决方法

有以下两种解决办法:

  • 重启所有manger节点
  • 重新选举出leader后即可恢复正常。

我选择了重新选举

(base) [[email protected] apps]# docker swarm init --force-new-cluster
Swarm initialized: current node (97u9dg2zc8sb6u5hrm68a7a0h) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-1nkdxehrdxg46n6b3mnp0j64hzf87k1lvdd3v522klmw5dsqwi-aqg0vj3ihmp2cd8ph0v8zbnpe 192.168.40.128:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

此时再执行docker node ls 就可以了

(base) [[email protected] apps]# docker node ls
ID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
97u9dg2zc8sb6u5hrm68a7a0h *   master     Ready     Active         Leader           20.10.8
sak742jquzrw0ifd21vqlyllw     slave1     Down      Active                          20.10.7
vt84s64qydcqbq1y94hvkw3yi     slave2     Down      Active                          1.13.1

此时service也可以正常启动了

(base) [[email protected] apps]# docker stack deploy -c eureka.yml eureka
Creating service eureka_eureka

问题解决

相关标签: docker docker