0

My project consists of a REST service, which is registered in Eureka, also I use Zuul proxy to manage requests as seen in this image. It runs perfectly on my computer in a local way but when I create a docker container for my service, it doesn't start. The steps I followed:

  • I created a Docker container for each service: Eureka server, Zuul API Gateway, the REST service and my Mysql database.
  • I get the data of my service from a stored procedure in the database, this conection was tested and it works.
  • I start all instances with docker-compose, Eureka and database instances remains up but the REST service instance stops abruptly. Zuul not is implemented yet.

The error:

matriculas-ms_1  | org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.eurekaClient' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.discovery.EurekaClient]: Factory method 'eurekaClient' threw exception; nested exception is java.lang.RuntimeException: Failed to initialize DiscoveryClient!

Here is the docker-compose.yml

version: '3.3'
services:
 srclbd:
  build: ./srclbd
  ports:
   - "3307:3306"
  expose:
   - "3306"
  volumes:
   - ./srclbd/data:/var/lib/mysql
 eureka:
  build: ./Eureka
  ports:
   - "8761:8761"
  expose:
   - "8761"
  matriculas-ms:
   build: ./matriculas-ms
   ports:
    - "3333:3333"
   expose:
    - "3333"
   depends_on:
    - srclbd
    - eureka
   links:
    - srclbd
    - eureka
   environment:
    - DATABASE_HOST=srclbd
    - EUREKA_HOST=eureka

Eureka's Dockerfile:

FROM java:8
ADD /target/eureka-0.0.1-SNAPSHOT.jar eureka-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","eureka-0.0.1-SNAPSHOT.jar"]

REST service Dockerfile:

FROM java:8
ADD /target/matriculas-service-0.0.1-SNAPSHOT.jar matriculas-service-     0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","matriculas-service-0.0.1-SNAPSHOT.jar","-Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n"]

Here is my project on github

Which is my error?

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
ladyy27
  • 1
  • 1

1 Answers1

0

Finally I solved my error setting up a separated configuration profile to Docker container like this:

spring:
 profiles: container
 application:
  name: matriculas-ms
jpa:
 hibernate:
  ddl-auto: none
datasource:
 url: jdbc:mysql://srclbd:3306/srcl?useSSL=false&noAccessToProcedureBodies=true
 username: root
 password: root
 initialize: true
eureka:
 client:
  serviceUrl:
   defaultZone: http://eureka:8761/eureka/
server:
 port: 1111

Then, I established this profile in the Dockerfile created to my REST service. So, every time it executes the JAR file, it will with the created profile's configuration.

FROM java:8
ADD /target/svcMatriculas.jar svcMatriculas.jar
ENTRYPOINT ["java","-Dspring.profiles.active=container","-jar","svcMatriculas.jar"]

Thanks!

ladyy27
  • 1
  • 1