尤里卡客户在docker不与尤里卡服务器连接

我有一个尤里卡服务器。

server: port: 8761 eureka: client: registerWithEureka: false fetchRegistry: false 

我有一个尤里卡客户。

 spring: application: name: mysearch server: port: 8020 eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka instance: preferIpAddress: true 

我的尤里卡客户端在docker集装箱中运行。

 FROM java:8 COPY ./mysearch.jar /var/tmp/app.jar EXPOSE 8180 CMD ["java","-jar","/var/tmp/app.jar"] 

我开始通过java -jar eureka-server.jar启动尤里卡服务器之后,我使用sudo docker build -t web .启动尤里卡客户端的docker实例sudo docker build -t web .sudo docker run -p 8180:8020 -it web 。 我能够从浏览器访问尤里卡客户端和服务器,但是客户端没有连接尤里卡服务器。 我无法在尤里卡服务器仪表板中看到客户端。 我得到错误和警告。

 WARN 1 --- [tbeatExecutor-0] cndstdRetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused) ERROR 1 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020 - was unable to send heartbeat! INFO 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020: registering service... ERROR 1 --- [nfoReplicator-0] cndstdRedirectingEurekaHttpClient : Request execution error WARN 1 --- [nfoReplicator-0] cndstdRetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused) WARN 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020 - registration failed Cannot execute request on any known server WARN 1 --- [nfoReplicator-0] cndiscovery.InstanceInfoReplicator : There was a problem with the instance info replicator 

我正在使用AWS EC2 Ubuntu实例。 任何人都可以告诉我我在做什么错在这里?

server:ports: – “8761:8761”eureka:client:registerWithEureka:false fetchRegistry:false

与上面的变化端口8761将在主机上,并可以连接到服务器。 作为您使用本地主机“ http:// localhost:8761 / eureka ”正在search主机上的端口8761连接。

在尤里卡客户端configuration使用主机IP而不是本地主机,因为如果localhost使用它在容器内search端口8761

HTTP://主机IP:8761 /尤里卡