【Docker】Docker Swarm连接出现connect: no route to host情况处理
程序员文章站
2022-03-12 18:53:27
...
问题
使用Docker Swarm集群部署在CentOS7
上时,当worker主机加入集群的时,发生如下错误:
[[email protected] ~]# docker swarm join --token SWMTKN-1-3b4hjen0t7fvxm7w94958pvgayo9pjewbr1r1mbyjkkkwrqoyr-atbt37va65u1emg05rmgfxyi2 192.168.21.131:2377
Error response from daemon: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 192.168.21.131:2377: connect: no route to host"
产生原因
端口没有开放
解决办法
办法1:
关闭Leader主机的防火墙
systemctl stop firewalld
办法2
放行连接端口(如上述2377)
#放行命令
firewall-cmd --zone=public --add-port=2377/tcp --permanent #放行2377端口
#其他命令
firewall-cmd --query-port=2377/tcp #查询2377端口是否开放
firewall-cmd --reload #重载防火墙
[[email protected] ~]# firewall-cmd --query-port=2377/tcp
no
[[email protected] ~]# firewall-cmd --zone=public --add-port=2377/tcp --permanent
success
[[email protected] ~]# firewall-cmd --reload
success
[[email protected] ~]# firewall-cmd --query-port=2377/tcp
yes
然后worker主机就可以加入集群了。
[[email protected] ~]# docker swarm join --token SWMTKN-1-3b4hjen0t7fvxm7w94958pvgayo9pjewbr1r1mbyjkkkwrqoyr-atbt37va65u1emg05rmgfxyi2 192.168.21.131:2377
This node joined a swarm as a worker.