微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么docker中的应用程序在eureka中像一些哈希而不是IP地址一样注册

如何解决为什么docker中的应用程序在eureka中像一些哈希而不是IP地址一样注册

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

这是来自尤里卡的信息

Eureka status

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

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

eureka:
  instance:
    preferIpAddress: true
  client:
    service-url:
      defaultZone: http://192.168.10.101:8761/eureka/

和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>

我可以以某种方式切换到IP地址吗?还是正确的情况? 谢谢!

UPD

当我尝试向网关服务发送请求时出现异常,该请求应路由到帐户服务

Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: account-service

解决方法

所以我将eureka的配置更改为

eureka:
  instance:
    preferIpAddress: true
  client:
    register-with-eureka: false
    fetch-registry: true
    server:
      waitTimeInMsWhenSyncEmpty: 0

获取注册表:true

效果很好

我在尤里卡有相同的服务描述

<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>

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

,

在运行 docker 时使用 --network host 它将选择主机 ip 地址

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。