Eureka client in docker not connecting with Eureka server Eureka client in docker not connecting with Eureka server docker docker

Eureka client in docker not connecting with Eureka server


Make sure you are running in Swarm mode.(Single node can also run Swarm)

$ docker swarm init

An overlay network is created so services can ping each other.

$ docker network create -d overlay mybridge

Set application.property for eurika client as below

eureka.client.service-url.defaultZone=http://discovery:8761/eureka

Now create first discovery service (Eureka discover server)

$ docker service create  -d --name discovery --network mybridge \    --replicas 1 -p 8761:8761 server-discovery

Open your browser and hit any node with port 8761

Now create client service:

$ docker service create  -d --name goodbyeapp --network mybridge \    --replicas 1 -p 2222:2222 goodbye-service

This will register to the discovery service.


server:  ports:      - "8761:8761"eureka:  client:    registerWithEureka: false    fetchRegistry: false

with the above changes port 8761 will expose on host and can connect to server.as your connecting using localhost "http://localhost:8761/eureka" which is searching for port 8761 on host.

In Eureka client config use host ip instead of localhost , because if localhost used it's search for port 8761 within container

http://hostip:8761/eureka


In the container world, the eureka server ip address can change each time the eureka server is restarted. Hence specifying the host ip address for eureka server url doesn't work all the time.

In the docker-compose.yml, I had to link the eureka client service to the eureka server container. Until I link the services, eureka client couldn't connect to the server.

This is already answered in another post recently: Applications not registering to eureka when using docker-compose