Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eureka client in docker not connecting with Eureka server

I have one eureka server.

server:
  port: 8761
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false

I have one eureka client.

spring:
  application:
    name: mysearch
server:
  port: 8020
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
  instance:
    preferIpAddress: true

My eureka client is running in a docker container.

FROM java:8
COPY ./mysearch.jar /var/tmp/app.jar
EXPOSE 8180
CMD ["java","-jar","/var/tmp/app.jar"]

I am starting the eureka server by java -jar eureka-server.jar After that I am starting the docker instance of the eureka client using sudo docker build -t web . and sudo docker run -p 8180:8020 -it web. I am able to access the eureka client and server from browser but the client is not connecting with Eureka server. I am not able to see the client in the eureka server dashboard. I am getting below errors and warnings.

WARN 1 --- [tbeatExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
ERROR 1 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020 - was unable to send heartbeat!
INFO 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020: registering service...
ERROR 1 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : Request execution error
WARN 1 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
WARN 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020 - registration failed Cannot execute request on any known server
WARN 1 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator     : There was a problem with the instance info replicator

I am doing it in an AWS EC2 Ubuntu instance. Can anyone please tell me what I am doing wrong here?

like image 419
Tanmoy Avatar asked Nov 28 '17 19:11

Tanmoy


2 Answers

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

like image 174
sanath meti Avatar answered Oct 03 '22 05:10

sanath meti


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.

like image 34
Muhammad Siddiqui Avatar answered Oct 03 '22 06:10

Muhammad Siddiqui