Docker启动容器报错: connect: no route to host
程序员文章站
2022-03-01 17:27:26
...
前言
笔者在重启了Docker服务后,发现其中一个api容器起不来了,这个容器在内部链接了另外一个MySQL容器,而那个MySQL容器是已经正常运行了。笔者通过docker logs container
查看api容器启动日志,发现了这个错误:
[ORM]2018/10/31 09:05:36 register db Ping `default`, dial tcp 192.168.1.54:3306: connect: no route to host
2018/10/31 09:05:36.636 [E] [command.go:54] 注册默认数据库失败: register db Ping `default`, dial tcp 192.168.1.54:3306: connect: no route to host
解决方案
通过在防火墙配置文件的增加一条规则,此问题得以解决,规则如下:
<rule family="ipv4">
<source address="172.17.0.0/16"/>
<accept/>
</rule>
其中address部分改为自己机器docker0网卡的ip地址,然后将规则加入防火墙配置:
[[email protected] /root]#cat /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected inco
ming connections are accepted.</description>
<service name="dhcpv6-client"/>
<service name="ssh"/>
<rule family="ipv4">
<source address="172.17.0.1/16"/>
<accept/>
</rule>
</zone>
然后重启防火墙:
[[email protected] /root]#systemctl restart firewalld.service
然后该容器就可以正常启动了,问题解决。
注意,如果防火墙会影响api服务的访问,做完这些操作时请记得停止防火墙服务;笔者在这里就给自己挖了一个坑,导致后台无法访问api,把防火墙停掉即可。
推荐阅读
-
no route to host (docker 容器访问宿主机)
-
Docker问题:容器互连时访问宿主机出现“No route to host”的问题
-
docker实践之从新镜像启动容器报错解决
-
BUG:Could not connect to Redis No route to host(redis集群报错)
-
docker实践之从新镜像启动容器报错解决
-
BUG:Could not connect to Redis No route to host(redis集群报错)
-
启动hadoop出现ssh: connect to host master port 22: No route to host 问题解决方案
-
kubectl get 报错:Unable to connect to the server: dial tcp 10.20.2.224:6443: connect: no route to host
-
【Docker】Docker Swarm连接出现connect: no route to host情况处理
-
Rsync同步报错【rsync: failed to connect to 192.168.8.152 (192.168.8.152): No route to host (113)】