Spring 为什么在eureka中docker寄存器中的应用程序喜欢一些散列而不是ip地址

Spring 为什么在eureka中docker寄存器中的应用程序喜欢一些散列而不是ip地址,spring,docker,spring-cloud,netflix-eureka,netflix-zuul,Spring,Docker,Spring Cloud,Netflix Eureka,Netflix Zuul,我需要告诉运行在Docker中的Eureka客户端使用主机的IP注册其服务。我用了下面的,但不起作用 这是来自尤里卡的信息 网关服务在没有docker容器的情况下运行,并且它具有IP地址而不是docker容器id 我有Eureka客户端的下一个配置(也有帐户服务) 和尤里卡配置: eureka: instance: preferIpAddress: true client: register-with-eureka: false fetch-registry:

我需要告诉运行在Docker中的Eureka客户端使用主机的IP注册其服务。我用了下面的,但不起作用

这是来自尤里卡的信息

网关服务在没有docker容器的情况下运行,并且它具有IP地址而不是docker容器id

我有Eureka客户端的下一个配置(也有帐户服务)

和尤里卡配置:

eureka:
  instance:
    preferIpAddress: true
  client:
    register-with-eureka: false
    fetch-registry: false
    server:
      waitTimeInMsWhenSyncEmpty: 0
帐户服务的Docker文件:

FROM openjdk:8-jdk-alpine
EXPOSE 8081
COPY /build/libs/account-service-1.0-SNAPSHOT.jar .
ENTRYPOINT ["java","-jar","account-service-1.0-SNAPSHOT.jar"]
如果我的理解正确,由于这个问题,网关服务也无法工作,因为它不知道任何具有a462e5bd6528(容器id)名称的主机

/帐户服务的eureka/app看起来像

<name>ACCOUNT-SERVICE</name>
<instance>
<instanceId>7186158a6d3a:account-service:8081</instanceId>
<hostName>172.17.0.2</hostName>
<app>ACCOUNT-SERVICE</app>
<ipAddr>172.17.0.2</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">8081</port>
<securePort enabled="false">443</securePort>
<countryId>1</countryId>
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1600017352414</registrationTimestamp>
<lastRenewalTimestamp>1600017472166</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1600017352415</serviceUpTimestamp>
</leaseInfo>
<metadata>
<management.port>8081</management.port>
</metadata>
<homePageUrl>http://172.17.0.2:8081/</homePageUrl>
<statusPageUrl>http://172.17.0.2:8081/accounts/actuator/info</statusPageUrl>
<healthCheckUrl>http://172.17.0.2:8081/accounts/actuator/health</healthCheckUrl>
<vipAddress>account-service</vipAddress>
<secureVipAddress>account-service</secureVipAddress>
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1600017352416</lastUpdatedTimestamp>
<lastDirtyTimestamp>1600017352218</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>
</application>

所以我将eureka配置更改为

eureka:
  instance:
    preferIpAddress: true
  client:
    register-with-eureka: false
    fetch-registry: true
    server:
      waitTimeInMsWhenSyncEmpty: 0
获取注册表:true

而且效果很好

我在Eureka有相同的服务描述

<name>ACCOUNT-SERVICE</name>
<instance>
<instanceId>4df8e2cd089d:account-service:8081</instanceId>
<hostName>172.18.0.5</hostName>
<app>ACCOUNT-SERVICE</app>
<ipAddr>172.18.0.5</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">8081</port>
<securePort enabled="false">443</securePort>
<countryId>1</countryId>
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1600182260927</registrationTimestamp>
<lastRenewalTimestamp>1600182500655</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1600182260391</serviceUpTimestamp>
</leaseInfo>
<metadata>
<management.port>8081</management.port>
</metadata>
<homePageUrl>http://172.18.0.5:8081/</homePageUrl>
<statusPageUrl>http://172.18.0.5:8081/accounts/actuator/info</statusPageUrl>
<healthCheckUrl>http://172.18.0.5:8081/accounts/actuator/health</healthCheckUrl>
<vipAddress>account-service</vipAddress>
<secureVipAddress>account-service</secureVipAddress>
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1600182260927</lastUpdatedTimestamp>
<lastDirtyTimestamp>1600182260267</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>
账户服务
4df8e2cd089d:帐户服务:8081
172.18.0.5
帐户服务
172.18.0.5
向上的
不为人知
8081
443
1.
我的
30
90
1600182260927
1600182500655
0
1600182260391
8081
http://172.18.0.5:8081/
http://172.18.0.5:8081/accounts/actuator/info
http://172.18.0.5:8081/accounts/actuator/health
帐户服务
帐户服务
假的
1600182260927
1600182260267
补充

但现在网关服务可以将请求路由到帐户服务

使用--网络主机运行docker时,它将选择主机ip地址

,这只是一个实例id,而不是注册的主机或ip。/eureka/apps怎么说?我已经用关于/eureka/apps say@spencer的信息更新了这个问题,所以主机名和ip地址注册为
172.17.0.2
Yep,但我需要我的本地ip地址,比如192.168.10.101。你需要设置它
eureka.instance.ip address=…
Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: account-service
<name>ACCOUNT-SERVICE</name>
<instance>
<instanceId>4df8e2cd089d:account-service:8081</instanceId>
<hostName>172.18.0.5</hostName>
<app>ACCOUNT-SERVICE</app>
<ipAddr>172.18.0.5</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">8081</port>
<securePort enabled="false">443</securePort>
<countryId>1</countryId>
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1600182260927</registrationTimestamp>
<lastRenewalTimestamp>1600182500655</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1600182260391</serviceUpTimestamp>
</leaseInfo>
<metadata>
<management.port>8081</management.port>
</metadata>
<homePageUrl>http://172.18.0.5:8081/</homePageUrl>
<statusPageUrl>http://172.18.0.5:8081/accounts/actuator/info</statusPageUrl>
<healthCheckUrl>http://172.18.0.5:8081/accounts/actuator/health</healthCheckUrl>
<vipAddress>account-service</vipAddress>
<secureVipAddress>account-service</secureVipAddress>
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1600182260927</lastUpdatedTimestamp>
<lastDirtyTimestamp>1600182260267</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>