I have microservices application, and i'm using Spring cloud and Spring boot v2.3 . i'm depending on config server and eureka, everything is working fine on my local machine from IDE, but when I deployed the stack on docker, my app Auth-Service cannot fetch from spring config server container, and give me the following stack trace
2020-07-05 02:23:52.888 INFO [auth-service,,,] 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-07-05 02:23:53.091 INFO [auth-service,,,] 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2020-07-05 02:23:53.092 WARN [auth-service,,,] 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/auth-service/default": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
I thought the issue is just waiting until or container-network as mentioned here Spring config is no accessible and this Microservices can't reach config service, but I ensured the containers are within same network, and to simulate, I started the config first, but got same error.
Here are the configurations i'm using
version: '3.8'
services:
eureka-service:
build:
context: ./eureka
image: eureka-service:latest
container_name: eureka
ports:
- 8761:8761
hostname: eureka
networks:
- mynetwork
config-service:
build:
context: ./configServer
image: config-server:latest
ports:
- 8888:8888
networks:
- mynetwork
proxy-service:
build:
context: ./web-cv-proxy
image: zuul-service:latest
ports:
- 8081:8081
depends_on:
- config-service
networks:
- mynetwork
auth-service:
build:
context: ./web-based-cv/auth-service
image: auth-service:latest
ports:
- 8060:8060
depends_on:
- config-service
- eureka-service
restart: on-failure
networks:
- mynetwork
portal-service:
build:
context: ./web-based-cv/cv-portal
image: cv-portal:latest
ports:
- 9090:9090
depends_on:
- config-service
- eureka-service
restart: on-failure
networks:
- mynetwork
networks:
mynetwork:
driver: bridge
Config server docker file
FROM java:openjdk-8-alpine
LABEL version="1.0"
LABEL description="configuration server"
COPY ./target/configServer-0.0.1-SNAPSHOT.jar ./
EXPOSE 8888
CMD ["java", "-jar", "configServer-0.0.1-SNAPSHOT.jar"]
Application docker file
FROM java:openjdk-8-alpine
LABEL version="1.0"
LABEL description="cv authintication service"
COPY ./target/auth-service-1.0.0-exec.jar auth-service-1.0.0-exec.jar
EXPOSE 8060
CMD ["java", "-jar", "/auth-service-1.0.0-exec.jar"]
The application bootstrap file
spring:
datasource:
jpa:
properties:
hibernate:
format_sql: true
ddl-auto: none
application:
name: auth-service
bus:
refresh:
enabled: true
profiles:
active: jdbc
cloud:
retry:
initial-interval: 1500
multiplier: 1.5
max-attempts: 10000
max-interval: 1000
server:
servlet:
context-path: /api/auth
port: 8060
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
register-with-eureka: true
fetch-registry: true
instance:
prefer-ip-address: true
management:
endpoints:
web:
exposure:
include: ["health","info","refresh", "bus-refresh"]
Your advice is highly appreciated , and thanks in advance.