Search code examples
spring-bootdockerdocker-composespring-cloudnetflix-eureka

Dockerize MIcro-Service is not register in Eureka Server


My micro-service is working fine. And in the development it's register properly in the Eureka-Naming server. When I deploy my service and eureka-server into two different container my micro- service is not registering in the eureka-server. All my configurations and properties files are given below--

Eureka-Service dockerfile-
------------------------------------------------------------------
FROM openjdk:8u181-jdk-stretch
MAINTAINER Test "support@softwaredeveloper.com"
EXPOSE 8761
COPY maven/netflix-eureka-naming-server-0.0.1-SNAPSHOT.jar 
netflix-eureka-naming-server.jar 
CMD ["java","-jar","netflix-eureka-naming-server.jar"]
------------------------------------------------------------

customer-account-mysql dockerfile-
-------------------------------------------------------------
FROM openjdk:8u181-jdk-stretch
MAINTAINER Test "support@softwaredeveloper.com"
EXPOSE 8100
COPY maven/customer-account-mysql-0.0.1-SNAPSHOT.jar customer- 
account-mysql.jar 
CMD ["java","-jar","customer-account-mysql.jar"]
---------------------------------------------------------------

Compose File for customer-account-mysql and Eureka Server
--------------------------------------------------------------
customer-account-mysql:
  image: customer-account-mysql
  networks: 
     - customer-network
  ports:
     - 8100:8100
  depends_on:
     - netflix-eureka-naming-server
netflix-eureka-naming-server:
  image: netflix-eureka-naming-server
  networks: 
     - customer-network
  ports:
     - 8761:8761
-------------------------------------------------------

Properties file of customer-account-mysql
-----------------------------------------------------
spring.application.name=customer-account-mysql
server.port=8100
eureka.client.service-url.default-zone=http://netflix-eureka- 
naming-server:8761/eureka/
------------------------------------------------------------

Properties file of eureka-server
---------------------------------------------------------
spring.application.name=netflix-eureka-naming-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.server.enableSelfPreservation=false

---------------------------------------------------------

But customer-account-mysql service is not registering in the 
Eureka-Server. I have inspect the log on the customer-account- 
mysql container.
Following error I was getting..
Error--------------
 ----------------------------------------------------------------
2019-02-06 06:27:33.248 ERROR [customer-account-mysql,,,] 1 --- 
[nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient  : 
Request execution error. endpoint=DefaultEndpoint{ 
serviceUrl='http://localhost:8761/eureka/}
com.sun.jersey.api.client.ClientHandlerException: 
java.net.ConnectException: Connection refused (Connection refused)
at com.sun.jersey.client.apache4.
ApacheHttpClient4Handler.handle(ApacheH 
ttpClient4Handler.java:187) ~[jersey-apache-client4- 
1.19.1.jar!/:1.19.1]
at 

----------------------------------------------------------------

My customer-account-mysql is trying to connect the http://localhost:8761/eureka/. Where I clearly mention the default zone in the customer-account-mysql properties file. That is eureka.client.service-url.default-zone=http://netflix-eureka- naming-server:8761/eureka/

Please help me to register my micro-service in the eureka 
server.

Solution

  • I think it should be eureka.client.serviceUrl.defaultZone as the documentation states, not eureka.client.service-url.default-zone. Your application is not using that property, so it fallback to the default value which is localhost:8761