spring-cloud-netflix: eureka instance won't use IP address in docker container

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 25 (7 by maintainers)

Most upvoted comments

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

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.

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

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.