Why application in docker register in eureka like some hash instead of ip address

Viewed 462

I need to tell a Eureka client running in Docker to use the host's IP to register its service. I used the below, but it doesn't work.

It's information from Eureka

Eureka status

Gateway service is running without docker container and it has IP address instead of docker container id.

I have next configuration for Eureka clients (account-service too)

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

And Eureka configuration:

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

Docker file for account-service:

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

If I understand right due to this problem it also gateway service does not work, because it doesn't know any host with a462e5bd6528 (container id) name

/eureka/app for account-service looks like

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

Can I somehow switch to IP address? Or is it correct situation? Thank you!

UPD:

And I got exception when try to send request to gateway service, which should route to account-service

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

So I've changed eureka configuration to

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

fetch-registry: true

And it works fine

I have the same service description in 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>

But now Gateway service can route requests to account-service

Use --network host when running the docker it will pick the host ip address

Related