Docker 环境 java.net.NoRouteToHostException: Host is unreachable (Host unreachable)

Caused by: java.net.NoRouteToHostException: Host is unreachable (Host unreachable)
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:301)
	... 141 common frames omitted

原因是 firewalld 的没有信任 docker 的 ip 地址,将所有 docker 的 ip 添加到信任区域。

[root@localhost ~]# firewall-cmd --zone=trusted --add-source=172.19.0.1/16 --permanent
success
[root@localhost ~]# firewall-cmd --zone=trusted --add-source=172.17.0.1/16 --permanent
success
[root@localhost ~]# firewall-cmd --zone=trusted --add-source=127.0.0.1/8 --permanent
success

重启防火墙

[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --complete-reload
success

查看添加结果

[root@localhost ~]# firewall-cmd --zone=trusted --list-sources
10.0.7.21 172.17.0.1 172.19.0.1/16 172.17.0.1/16 127.0.0.1/8

最后,重新启动容器即可。

完毕

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐