Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Java Spring Cloud Cannot register any service to Eureka Server in Docker through docker-compose.yml

datdatyul

Active Coder
I'm trying to implement an example of **Spring Cloud** with its all services running in **Docker**.

I cannot register any service to **eureka server** as **eureka server** throws a connection issue in **Docker**.

When I show the **logs** of **eureka server** through this command (**docker logs <eureka-service-container-id>**), I got the error.

Here is the error shown below.

Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eu
reka/}, exception=java.net.ConnectException: Connection refused (Connection refused) stacktrace=com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection
refused (Connection refused)

How can I fix that?

Here is **docker-compose.yml** shown below.

services:

database:
container_name: mysql-database
image: 'mysql:latest'
ports:
- "3366:3306"
restart: always
environment:
#MYSQL_DATABASE: "springbootuser"
MYSQL_USER: "springmicroserviceuser"
MYSQL_PASSWORD: "111111"
MYSQL_ROOT_PASSWORD: "111111"
volumes:
- db-data:/var/lib/mysql
networks:
- backend
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10

keycloak:
image: quay.io/keycloak/keycloak:18.0.2
environment:
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin
ports:
- "8181:8080"
networks:
- backend
command:
- start-dev

rabbitmq:
image: "rabbitmq:3-management"
container_name: "rmq3"
environment:
RABBITMQ_DEFAULT_USER: "rabbitmq"
RABBITMQ_DEFAULT_PASS: "123456"
ports:
- "5672:5672"
- "15672:15672"
networks:
- backend

configserver:
image: configserver
container_name: configServer
build:
context: ./configserver
dockerfile: Dockerfile
environment:
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
ports:
- "9191:9191"
networks:
- backend

eurekaserver:
image: eurekaserver
ports:
- "8761:8761"
build:
context: ./discoveryserver
dockerfile: Dockerfile
environment:
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
WAIT_HOSTS: configserver:9191
depends_on:
configserver:
condition: service_started
networks:
- backend


gatewayserver:
image: gatewayserver
ports:
- "8600:8600"
build:
context: ./api-gateway
dockerfile: Dockerfile
environment:
PROFILE: "default"
SERVER_PORT: "8600"
CONFIGSERVER_URI: "http://configserver:9191"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
CONFIGSERVER_PORT: "9191"
WAIT_HOSTS: configserver:9191
depends_on:
configserver:
condition: service_started
eurekaserver:
condition: service_started
networks:
- backend

userservice:
image: user-service
build:
context: ./user-service
dockerfile: Dockerfile
environment:
SERVER_PORT: "9000"
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
WAIT_HOSTS: configserver:9191
DATABASE_HOST: database
DATABASE_USER: springmicroserviceuser
DATABASE_PASSWORD: 111111
DATABASE_NAME: springbootuser
DATABASE_PORT: 3306
SPRING_APPLICATION_JSON: '{
"spring.jpa.hibernate.ddl-auto" : "update"
}'
depends_on:
database:
condition: service_healthy
configserver:
condition: service_started
ports:
- "9000:9000"
networks:
- backend

managementservice:
image: management-service
build:
context: ./management-service
dockerfile: Dockerfile
environment:
SERVER_PORT: "9002"
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
WAIT_HOSTS: configserver:9191
depends_on:
configserver:
condition: service_started
advertisementservice:
condition: service_started
reportservice:
condition: service_started
ports:
- "9002:9002"
networks:
- backend

advertisementservice:
image: advertisement-service
build:
context: ./advertisement-service
dockerfile: Dockerfile
environment:
SERVER_PORT: "9001"
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
WAIT_HOSTS: configserver:9191
DATABASE_HOST: database
DATABASE_USER: springmicroserviceuser
DATABASE_PASSWORD: 111111
DATABASE_NAME: springbootadvertisement
DATABASE_PORT: 3306
SPRING_APPLICATION_JSON: '{
"spring.jpa.hibernate.ddl-auto" : "update"
}'
depends_on:
database:
condition: service_healthy
configserver:
condition: service_started
ports:
- "9001:9001"
networks:
- backend


reportservice:
image: report-service
build:
context: ./report-service
dockerfile: Dockerfile
environment:
SERVER_PORT: "9003"
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
WAIT_HOSTS: configserver:9191
DATABASE_HOST: database
DATABASE_USER: springmicroserviceuser
DATABASE_PASSWORD: 111111
DATABASE_NAME: springbootreport
DATABASE_PORT: 3306
SPRING_APPLICATION_JSON: '{
"spring.jpa.hibernate.ddl-auto" : "update"
}'
depends_on:
database:
condition: service_healthy
configserver:
condition: service_started
ports:
- "9003:9003"
networks:
- backend

networks:
backend:
driver: bridge


volumes:
db-data:

Here is **application.properties** of eureka server shown below.

spring.application.name=discovery-server
eureka.instance.hostname=eurekaserver
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://eurekaserver:8761/eureka/
server.port=8761
logging.level.org.springframework.cloud.commons.util.InetUtils=TRACE

Here is the **project** link : Link
 

Buy us a coffee!

Back
Top Bottom