How can I connect the eureka server and eureka client using docker compose? I have simple client with application.yml
where configured the configurations for connection to eureka server:
spring:
jackson:
serialization:
fail-on-empty-beans: false
application:
name: usersMicro
jpa:
show-sql: true
database: POSTGRESQL
hibernate:
ddl-auto: create-drop
datasource:
url: jdbc:postgresql://localhost:5432/my_test_db
username: root
password: admin
driver-class-name: org.postgresql.Driver
server:
port: 8089
#eureka:
# client:
# serviceURL:
# defaultZone: http://localhost:8761/eureka/
eureka:
client:
serviceURL:
defaultZone: http://localhost:8761/eureka/
service-url:
zone1: http://localhost:8761/eureka/
region: region-1
availability-zones:
region-1: zone1
the standard eureka client Dockerfile
:
FROM ubuntu:latest
LABEL authors="user"
ENTRYPOINT ["top", "-b"]
FROM openjdk:17-jdk-slim
VOLUME /tmp
COPY target/usersMicro-1.jar user-service.jar
ENTRYPOINT ["java","-jar","/user-service.jar"]
and docker-compose.yml
file:
version: "3.9"
services:
user-service:
container_name: user-service
image: user-service
restart: unless-stopped
build:
context: .
dockerfile: Dockerfile
ports:
- "8089:8089"
networks:
- postgres
networks:
postgres:
name: shared-network
external: true
The eureka server is almost the same
the server eureka application.yml
is:
spring:
application:
name: eureka_server
server:
port:
- "8761:8761"
eureka:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
eureka server Dockerfile
is the same, except lines
COPY target/eureka_server-1.jar eureka-server.jar
ENTRYPOINT ["java","-jar","/eureka-server.jar"]
and eureka server docker-compose.yml
file:
version: '3.9'
services:
# EUREKA-SERVER CONTAINER............................................
eureka_server-service:
container_name: eureka_server
image: eureka_server
restart: on-failure
build:
context: .
dockerfile: Dockerfile
ports:
- "8761:8761"
networks:
- postgres
# NETWORKS CONFIGURATION....................................................
networks:
postgres:
name: shared-network
external: true
My docker-compose
files for server and client are in different directories and may be that is the problem, that they should be specified in the same file, but I was able to connect my microservices with DB which is in a strict different drive.
If I start the server and client out of docker, from IDE, I am able to see the connection in eureka web interface, but if docker – in logs, I receive the error that connection refused:
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
or 2024-08-06T13:28:24.835500447Z Caused by: org.apache.hc.client5.http.HttpHostConnectException: Connect to http://localhost:8761 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused
what I miss in these configurations ?