Springboot client unable register with Eureka using Docker container id

docker eureka client connection refused
eureka/docker-compose
spring boot microservices with docker-compose example
spring boot microservices with docker example
eureka vs docker
eureka client service url
eureka instance: preferipaddress
eureka server default username and password

I have several microservices running in Docker Data Center. I have the same Eureka configuration across the services/applications. But some of the applications are registering with their eth0 IP address instead of the container ID.

I have tried setting the preferIpAddress as false but it is not enforcing all the time.

There is no pattern. The same service which registers with container ID during the previous deployment gets registered with IP the other time. I want my services to register always with its container id. Is there a way to enforce it or am I missing something?

Note: I have also cleared all the old docker images from the registry, deployment nodes and tried from the scratch as well.

Eureka Server Config:

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

Microservices client config (It is same across all the 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 Dashboard Snapshot:

In docker the container-id will be set as the hostname of the container by default. Containers can talk with each other using container-id (or here hostname)

So this issue can be solved by preferring hostname instead of ip.

But only way of making sure that registration happens through hostname is by setting eureka.instance.hostname reference

In docker you can set the container-id at run-time from the hostname by using the entry point as shell script (for example start.sh) and the script should be something similar to

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

and make sure you add eureka.instance.hostname=${HOST_NAME} in your application.yml

or you can reuse the HOSTNAME variable which is set by default in Docker and configuration becomes eureka.instance.hostname=${HOSTNAME}

I have added the same info in documentation

Update: looks like this can also be fixed by using endpoint_mode: dnsrr in the compose file (have to confirm). Refer this

Need to tell eureka client running in Docker to use host's IP · Issue , I am running a Spring Cloud application inside a Docker container. 8081) , it doesn't seem to let you tell it to register using the host's ip address. the Docker container during its boot process and assign the hostname to an  when running as direct spring boot apps, it works fine and registers client using IP address to eureka server. But when i run client as docker container, it always uses docker container id to register in eureka server. I am using docker for mac version 1.13.1. and spring boot version 1.4.1.

Try setting eureka.instance.hostname in your client config.

eureka client don't use ip address in docker container · Issue #1710 , i have created simple spring cloud app with eureka server and client registering to eureka it always uses docker container id to register in eureka server. I am using docker for mac version 1.13.1. and spring boot version  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.

I know this is an old question but this answer might be helpful to someone. After trying out a number of solutions, I noticed that a hostname environment variable(HOSTNAME) already exists in Ubuntu. My docker containers use the openjdk:8-jdk-alpine base. If you're using an Ubuntu base you can simply solve this issue by adding the following parameters to the properties files of all your eureka clients:

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

The app will pick up the container's hostname which is the container id and pass that to the eureka server.

Spring Cloud and Spring Boot, Part 5: Deploying the Eureka Server , Docker is a software platform or tool allows you to create, deploy, or run the application by using containers. Docker allows developers to  While I can tell Eureka to use the exposed port (e.g. EUREKA_INSTANCE_NON_SECURE_PORT: 8081) , it doesn't seem to let you tell it to register using the host's ip address. Instead, eureka registers the instance using the container's ip address. That fine unless I want to access the container from another host.

Build Spring Microservices and Dockerize Them for Production , The icing on the cake will be authentication integration using Spring Profiles; you will Finally, each project will be transformed into a Docker image. The school​-service directory contains a Spring Boot project that acts as the eureka.client.​register-with-eureka - Tells Spring not to register itself into the  Docker is a Linux container management toolkit with a "social" aspect, allowing users to publish container images and consume those published by others. A Docker image is a recipe for running a containerized process, and in this guide we will build one for a simple Spring boot application.

Microservice Registration and Discovery with Spring Cloud and , The burden is on the client to manage this intrinsic complexity. You probably already use a technology that has some notion of a cluster Spring Cloud already supports both Eureka and Consul, though I'll focus on Eureka in variables in your manifest.yml or, on Cloud Foundry Lattice, your Docker file. Here discovery-eureka is the docker service name (In docker swarm you can hit the containers using the service name) and we have only one instance (container) of eureka running. This comment has been minimized.

Eureka, Both Zuul and Eureka are part of the Spring Cloud Netflix project. Using the names of the storefront's Docker containers, you can check the start-up logs client = MongoClient('mongodb://localhost:27017/') Stand-alone Spring Boot application provides service discovery and registration for failover and load-​balancing. I have a spring boot MS as euureka client, register to eureka service and a zuul gateway and all works fine except one single point. As docker container the eureka client is registered with the original port. But for real there is a port mapping and this one should be used for register to eureka service.

Comments
  • if you do this how do you register your eureka containers with each other for HA, and how do your microservice clients register with Eureka if the hostname is being used and it isnt known til launch time? Are you using AWS and autoscaling or is everything in your environment pre determined?