springspring-bootdockerdocker-composespring-cloud-config-server

Spring micro services eureka client is not registering with eureka server


I'm very new to everything about docker, spring framework... They run on localhost environment successfully, now I want to push them into docker, but always gave me error there, i got stuck on it about a week. Can someone help me figure it out PLEASE!!!

now I have eureka-server and cloud-config-server services, here is my code:

eureka-server application.yml

server:
  port: 8761
spring:
  application:
    name: service-registration
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
management:
  security:
    enabled: false

and Dockerfile:

FROM openjdk:11
COPY target/service-registration-0.0.1-SNAPSHOT.jar service-registration.jar
EXPOSE 8761
CMD ["java", "-jar", "service-registration.jar"]

Now I have cloud-config-server application.yml: In this file, i tried to backup it on github. From the start, I tried to change the hostname as localhost or any other hostname like service-registration, eureka-server etc... but not work, and "service-url" or "serviceUrl'....

server:
  port: 9291

spring:
  application:
    name: cloud-config-server
  profiles:
    active: production
#  cloud:
#    config:
#      server:
#        git:
#          uri: https://github.com/sshaunn/config-server
#          clone-on-start: true

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://service-registration:8761/eureka/
  instance:
#    prefer-ip-address: true
#    ip-address: http://eureka-server:8761/eureka/å
    hostname: service-registration

Dockerfile:

FROM openjdk:11
COPY target/cloud-config-server-0.0.1-SNAPSHOT.jar cloud-config-server.jar
EXPOSE 9291
ENTRYPOINT ["java", "-jar", "cloud-config-server.jar"]

and the docker-compose.yml file:

version: '3.7'
services:
  service-registration:
    image: service-registration
    networks:
      - eureka-server
    ports:
      - "8761:8761"
    container_name: service-registration
    hostname: service-registration
  cloud-config-server:
    build: cloud-config-server
    networks:
      - eureka-server
    ports:
      - "9291:9291"
    depends_on:
      - service-registration
    container_name: cloud-config-server
    hostname: service-registration
    environment:
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://service-registration:8761/eureka

networks:
  eureka-server:
    name: eureka-server
    driver: bridge
#  route:
#    image: route
#    ports:
#      - "9191:9191"
#    container_name: api-gateway

#    environment:
#      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://service-registration:8761/eureka

here is the ui of eureka server The error logs here:

2022-05-29 07:22:41.713 WARN 1 --- [freshExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused (Connection refused); 2022-05-29 07:06:11.565 WARN 1 --- [tbeatExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: I/O error on PUT request for "http://localhost:8761/eureka/apps/CONFIG-SERVER/service-registration:CONFIG-SERVER:9291": Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused (Connection refused);


Solution

  • Ok, I dont know why but I set up a docker-compose.yml file like this and it works: Note, I set up environment about "service-url" defaultZone in docker-compose.yml file.

    version: '3.7'
    services:
      service-registration:
        container_name: service-registration
        build:
          context: ./service-registration
          dockerfile: Dockerfile
        ports:
          - "8761:8761"
      cloud-config-server:
        container_name: cloud-config-server
        build:
          context: ./cloud-config-server
          dockerfile: Dockerfile
        environment:
          - eureka.client.service-url.defaultZone=http://service-registration:8761/eureka
        depends_on:
          - service-registration
        ports:
          - "9191:9191"
      route:
        container_name: route
        build:
          context: ./route
          dockerfile: Dockerfile
        environment:
          - eureka.client.service-url.defaultZone=http://service-registration:8761/eureka
        depends_on:
          - service-registration
          - employee
          - income
        ports:
          - "9291:9291"
      employee:
        container_name: employee
        build:
          context: ./employee
          dockerfile: Dockerfile
        environment:
          - eureka.client.service-url.defaultZone=http://service-registration:8761/eureka
        depends_on:
          - service-registration
        ports:
          - "9001:9001"
      income:
        container_name: income
        build:
          context: ./income
          dockerfile: Dockerfile
        environment:
          - eureka.client.service-url.defaultZone=http://service-registration:8761/eureka
        depends_on:
          - service-registration
        ports:
          - "9002:9002"