Springboot client cannot register with Eureka using Docker container id

I have several microservices working in the Docker Data Center. I have the same Eureka configuration across all services / applications. But some of the applications are registered with their IP address eth0instead of the container identifier.

I tried to set preferIpAddresshow false, but it does not work all the time.

There is no template. The same service that is registered with the container identifier during the previous deployment is registered in IP at another time. I want my services to always register with the container identifier. Is there a way to enforce it or am I missing something?

Note. I also cleaned all the old docker images from the registry, deployment nodes, and tried from scratch.

Eureka Server Configuration:

eureka:
  instance:
    hostname: discovery
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:8761/eureka/

Microservices client configuration (it is the same for all microservices)

eureka:
  client:
    healthcheck:
      enabled: true
    serviceUrl:
      defaultZone: http://discovery:8761/eureka/
  instance:
    preferIpAddress: false
    metadataMap:
      instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}

Eureka toolbar snapshot: enter image description here

+5
source share
4 answers

In docker, the container identifier will be set as the default host name of the container. Containers can communicate with each other using the container identifier (or host name here)

So this problem can be solved by choosing the host name instead of the ip name.

But the only way to make sure that registration is through the host name is to set a link eureka.instance.hostname

Docker , (, start.sh), -

#!/bin/sh
export HOST_NAME='hostname'
java -Djava.security.egd=file:/dev/./urandom -Xmx1024m -jar /app.jar

, eureka.instance.hostname=${HOST_NAME} application.yml

HOSTNAME Docker, eureka.instance.hostname=${HOSTNAME}

: , endpoint_mode: dnsrr compose ( ).

+4

eureka.instance.hostname .

+2

, , -. , , (HOSTNAME) Ubuntu. - openjdk:8-jdk-alpine. Ubuntu, , eureka:

eureka.instance.hostname=${HOSTNAME}
spring.cloud.client.hostname=${HOSTNAME}

, , eureka.

+2

@Dhanvi: hostname Dockerfile, , bash.

Dockerfile:

RUN export HOST_NAME='hostname'

application.yml:

eureka.instance.preferIpAddress: false
eureka.instance.hostname=${HOST_NAME}
-1

Source: https://habr.com/ru/post/1679854/


All Articles