gpt4 book ai didi

docker - Docker容器NoRouteToHostException:主机不可访问

转载 作者:行者123 更新时间:2023-12-02 18:35:05 24 4
gpt4 key购买 nike

我在CentOS-8上,有几个spring-boot服务:demo-client通过spring RestTemplate通过HTTP调用demo-server。没有Docker容器,这可以正常工作。
但是当我使用默认网络将它们部署为docker-compose时,demo-client无法调用demo-server。我尝试使用容器的服务名称和IP地址,但在两种情况下都出现相同的错误:

demo-client_1  | 2020-02-29 10:23:55.165 ERROR 1 --- [nio-8082-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: **I/O error on GET request for "http://172.24.0.2:8081/hello": Host is unreachable (Host unreachable);** nested exception is java.net.NoRouteToHostException: Host is unreachable (Host unreachable)] with root causedemo-client_1  | demo-client_1  | java.net.NoRouteToHostException: Host is unreachable (Host unreachable)demo-client_1  |    at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_212]demo-client_1  |    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_212]*

Docker compose file :

docker-compose.yml:
version: '3'
services:
demo-client:
build: ./demo-client
ports:
- "8082:8082"
depends_on:
- demo-server
demo-server:
build: ./demo-server
ports:
- "8081:8081"

我尝试了一些早期帖子中建议的与防火墙相关的操作:
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload
firewall-cmd --permanent --zone=trusted --add-interface=docker0
firewall-cmd --reload
service firewalld restart*

这些都不起作用。我认为直截了当的事情变得更加复杂。

最佳答案

问题出在Centos-8上,而相同的代码在CentOS-7上运行良好。因此,现在我回到了Centos-7。
CentOS-8引入Podman作为官方容器工具而不是Docker

关于docker - Docker容器NoRouteToHostException:主机不可访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60464748/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com