Hi,

I'm working on a small spring boot web service which has to register against an eureka server (also written as Spring Boot application). This is my configuration:

spring:
  application.name: awesomeservice
eureka:
  client:
    serviceUrl:
      defaultZone: http://10.0.0.3:8761/eureka/
---
spring:
  profiles: docker
eureka.instance.preferIpAddress: true

When running as docker container my service should prefer to register with its IP address instead of the hostname ... but it will always use the docker container id (which is the hostname i guess) when I start it using docker-compose.

Neither setting the euereka.instance.hostname nor ipAddress attribute helps. The docker profile is loaded correctly ... looking forward for tips, hints and answers here.

Kind regards, codecitizen

Comment From: ryanjbaxter

How are you determining that it is using the hostname rather than the IP address?

Comment From: codecitizen

Hi @ryanjbaxter

screen shot 2017-01-25 at 15 16 25

In the Web Interface of my Eureka Server it links the hostname

Comment From: ryanjbaxter

Those are just instance ids. If you hover over the links in the browser, or inspect them using the browser developer tools, what do they link to?

Comment From: codecitizen

The instance with the id 54814d8e4a23 links to http://54814d8e4a23:8080/info

Comment From: ryanjbaxter

Ah I think you have the wrong property, I think it should be 'eureka.client.instance.preferIpAddress'

Comment From: codecitizen

The documentation says eureka.instance.preferIpAddress

Comment From: ryanjbaxter

You are right, it is hard to read YAML on your phone sometimes :)

It is not obvious to me why it is not working, can you provide a sample that reproduces the problem?

Comment From: spencergibb

What does /eureka/apps say?

Comment From: spencergibb

Also, what does /env say? To make sure your property was applied.

Comment From: codecitizen

Works now. This morning I rebuilt the the library and docker image and redeployed it to a newly initialized dev system. It registered against the eureka server with the IP Address, everything is fine. I did some testing, pulled up more services, each registered correctly. So there was probably some issue in my build pipeline. Sorry for bothering.

@spencergibb sorry I can't check the old service for /eureka/apps or /env ... but yesterday I was debugging through EurekaInstanceConfigBean#getHostname(boolean) and it was showing the right values for preferIpAddress and ipAddress.

Comment From: kimjuny

@codecitizen Hi, could you please pin your application.yml here (only the essential part) of your eureka server and client? I am facing exactly same problem, and I've tried many times not succeeded yet.

Comment From: eacdy

I think you should use eureka.instance.instance-id

Comment From: makdeniss

I also have this problem. Tried a lot of things, but everything failed.

Comment From: radhey7

@codecitizen Hi, Please share your application.yml file

Comment From: makdeniss

IF anybody is interested I found the solution. Client services need to have this in their application.properties (or similiar .yml structure):

eureka.instance.prefer-ip-address=true
eureka.instance.ip-address=IP_OF_MACHINE_ON_WHICH_RUNNING
eureka.instance.instance-eureka.instance.instance-id=eureka.instance.instance-id=${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}

Comment From: radhey7

@makdeniss ..can you please share your facebook id

Comment From: radhey7

i want to communicate with you ....i am facing the same problem ..but everything failed

Comment From: makdeniss

my nick is my skypeid.

Comment From: radhey7

@makdeniss i am unable to understand your last line eureka.instance.instance-id=eureka.instance.instance-id=${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}

Comment From: radhey7

sent skype request ..please accept

Comment From: kimjuny

Hi, it seems network inside docker is rather complex, I can't explain why by this perfectly fixes my problem.

spring:
  application:
    name: stock-service
  cloud:
    inetutils:
      ignored-interfaces:
        - eth0
        - eth1
        - eth2
        - eth3
        - lo

Let me know if this also fixes yours.

Comment From: MARudnicki

Hi. I found the following solution. First add the following code in configuration or service that will be searched

@Autowired
    InetUtils inetUtils;

    @Bean
//    @Profile("!default")
    public EurekaInstanceConfigBean eurekaInstanceConfig() {

        log.info("\n\n creating eureka instance  \n\n\n");

        EurekaInstanceConfigBean b = new EurekaInstanceConfigBean(inetUtils);
        AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
        b.setDataCenterInfo(info);
        return b;
    }

Then you can access the right ip of your service using

       String ip = ((AmazonInfo)discoveryClient.getNextServerFromEureka("ADMIN-APPLICATION",false)
                .getDataCenterInfo())
                .getMetadata().get("public-ipv4");

What was very useful is the endpoint <EUREKA_URL>/eureka/apps with listed all information about registered services

Comment From: abhilashgopal

Hi,

I'm facing the same issue. My service is getting registered with Eureka with Docker container IP. I want it to get registered with the host machine IP address. I tried ignoring network interfaces too. It is still not working. Any help would be appreciated.

Thanks.

Comment From: AnthonyCavanagh

It seems weird that to get this running, there is not the solution, but there are lots of what looks like hacks,

Comment From: AJ198081

Try defining the property - eureka.instance.hostname=http://${server.address}:${server.port} where server. address and server. port are defined separately.

It may work for you.