无法从Docker连接到Eureka服务器

时间:2019-05-26 10:39:32

标签: spring-boot docker netflix-eureka

我正在尝试从Docker容器连接到eureka服务器。

eureka服务器正在通过“ java -jar eureka-server.jar”命令运行。 eureka客户端正在docker容器上运行。

Eureka服务器配置为:

eureka:
  instance:
    hostname: eurekaserver
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://eurekaserver:8080/eureka/

Eureka客户端配置为:

spring:
  application:
    name: client-application
server:
  port: 8081
eureka:
  client:
    serviceUrl:
      defaultZone: http://eurekaserver:8080/eureka/

例如,我也尝试直接设置ip-address

eureka:
  client:
    serviceUrl:
      defaultZone: http://1.2.3.4:8080/eureka/

但是,不幸的是,我面临着堆栈跟踪:

[2019-05-26 09:44:14.714] slf4j - 1  INFO [main] --- o.a.h.i.c.DefaultHttpClient: Retrying connect to {}-> http://eurekaserver:8080
[2019-05-26 09:44:15.717] slf4j - 1 ERROR [main] --- c.n.d.s.t.d.RedirectingEurekaHttpClient: Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.NoRouteToHostException: No route to host (Host unreachable)
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)
    at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)
    at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)
    at com.sun.jersey.api.client.Client.handle(Client.java:652)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
    at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509)
    ...
Caused by: java.net.NoRouteToHostException: No route to host (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 org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144)
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:117)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173)
    ... 72 common frames omitted

这是

的原因
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

所以我的问题是如何解决连通性? Docker和eureka放在同一台机器上,因为命令curl "http://1.2.3.4:8080/eureka/apps"将应用返回给我

我该如何进行调查,为什么Docker无法解析主机?

p.s。我已经知道了这个问题,当eureka-client查看本地主机名时,却又像我的问题一样。

谢谢。

1 个答案:

答案 0 :(得分:0)

已解决。 问题的原因是,不要使用

self.right.insert_node(...)

更多信息,请在Google中输入属性名称后首先找到链接

但是,如果使用它们,则必须将self设置为主机名,并添加 registerWithEureka: true fetchRegistry: true

p.s。不确定完全可以解决此问题,但是我在应用程序配置中进行了更改。