Search code examples
dockerspring-clouddocker-swarmspring-cloud-netflix

Application registers in Eureka using IP instead of hostname when its Docker container publishes port


I dockerize my Spring Boot application and deploy to Docker Swarm.

If I do not publish the port my app exposes, then Eureka client sends the hostname as an address of the instance, like http://ecf28bdd26c5:8080 - good

If I publish the port (using Docker's --publish parameter), then it registers with IP, like http://10.255.0.25:8080 - bad

It does so even if I explicitly set eureka.instance.prefer-ip-address=false.

How can I force Eureka client to really use hostname?


Solution

  • by explicitly setting the hostname eureka.instance.hostname=${SOME_VAR} or ignoring certain interfaces:

    From the documentation: The following configuration will ignore the "docker0" interface and all interfaces that start with "veth".

    application.yml
    spring:
      cloud:
        inetutils:
          ignoredInterfaces:
            - docker0
            - veth.*
    

    You can also force to use only specified network addresses using list of regular expressions:

    application.yml
    spring:
      cloud:
        inetutils:
          preferredNetworks:
            - 192.168
            - 10.0