简体   繁体   English

Docker 容器 NoRouteToHostException:主机无法访问

[英]Docker Containers NoRouteToHostException: Host is unreachable

I am on CentOS-8 and have a couple of spring-boot services: demo-client calls demo-server over HTTP through spring RestTemplate.我在 CentOS-8 上有几个 spring-boot 服务:演示客户端通过 spring RestTemplate 通过 HTTP 调用演示服务器。 This works fine without Docker container.这在没有 Docker 容器的情况下工作正常。 But when I deploy them as docker-compose with default network, demo-client is not able to call demo-server.但是当我使用默认网络将它们部署为 docker-compose 时,演示客户端无法调用演示服务器。 I tried with service-name and also with ip-address of the container but same error in both cases:我尝试使用 service-name 和容器的 ip-address 但在两种情况下都出现相同的错误:

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 cause
demo-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 撰写文件:

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"

I tried following firewall related actions as suggested in some of the earlier posts:我尝试按照之前一些帖子中的建议执行与防火墙相关的操作:

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*

None of this worked.这些都没有奏效。 What I thought to be a straight forward thing turned out to be more complex.我认为是一件直截了当的事情,结果变得更加复杂。

The issue is with Centos-8 and The same code worked fine with CentOS-7.问题出在 Centos-8 上,同样的代码在 CentOS-7 上运行良好。 so, for now I moved back to Centos-7.所以,现在我搬回 Centos-7。 CentOS-8 introduced Podman as official container tool instead of Docker CentOS-8 引入 Podman 作为官方容器工具而不是 Docker

In my case firewall blocking elastic port from the container.在我的情况下,防火墙阻止了来自容器的弹性端口。 I stopped the firewall and restarted the application it worked.我停止了防火墙并重新启动了它工作的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM