I am using a spring cloud config server to externalize the configuration properties for my project
For this purpose I have created two microservices
- configserver
- accounts
when I am trying to create and start the containers using the docker compose up file, I am getting below exception
024-06-14 08:59:34 2024-06-14T03:29:34.350Z WARN 1 — [cards] [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Could not locate PropertySource ([ConfigServerConfigDataResource@473b3b7a uris = array[‘http://localhost:8071/’], optional = true, profiles = ‘default’]): I/O error on GET request for “http://localhost:8071/accounts/default”: Connection refused.
Please note the configserver and rabbitmq both are getting started but account,loans and cards are getting exited due to the same error.
Also If I use the configserver as a container and start the loans,cards or accounts ms directly from IDE i am able to connect.
application.yaml for configserver
spring:
application:
name: configserver
profiles:
#active: native
active: git
cloud:
config:
server:
#native:
#search-locations: “classpath:/config”
#search-locations: “file:///D:/code/elearn_eazybank/section6/config-filepath”
git:
uri: “actual URL removed due to confidentaility”
default-label: main
timeout: 5
clone-on-start: true
force-pull: true
management:
endpoints:
web:
exposure:
include: “*”
health:
readiness-state:
enabled: true
liveness-state:
enabled: true
endpoint:
health:
probes:
enabled: true
encypt:
key: “45D81EC1EF61DF9AD8D3E5BB397F9”
server:
port: 8071
application.yaml for accounts
server:
port: 8080
logging:
level:
org:
springframework:
web: “DEBUG”
spring:
application:
name: “accounts”
profiles:
active: “prod”
datasource:
url: jdbc:h2:mem:testdb
driverClassName: org.h2.Driver
username: sa
password: ”
h2:
console:
enabled: true
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
show-sql: true
config:
import: “configserver:http://localhost:8071/”
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
management:
endpoints:
web:
exposure:
include: “*”
**docker-compose.yaml **
services:
rabbit:
image: rabbitmq:3.13-management
hostname: rabbitmq
ports:
– “5672:5672”
– “15672:15672”
healthcheck:
test: rabbitmq-diagnostics check_port_connectivity
interval: 10s
timeout: 5s
retries: 10
start_period: 5s
extends:
file: common-config.yaml
service: network-deploy-service
configserver:
image: “dockerhub image name”
container_name: configserver-ms
ports:
– “8071:8071”
depends_on:
rabbit:
condition: service_healthy
healthcheck:
test: “curl –fail –silent localhost:8071/actuator/health/readiness | grep UP || exit 1”
interval: 10s
timeout: 5s
retries: 10
start_period: 10s
extends:
file: common-config.yaml
service: microservice-base-config
accounts:
image: “dockerhub image name”
container_name: accounts-ms
ports:
– “8080:8080”
depends_on:
configserver:
condition: service_healthy
environment:
SPRING_APPLICATION_NAME: “accounts”
extends:
file: common-config.yaml
service: microservice-configserver-config
loans:
image: “dockerhub image name”
container_name: loans-ms
ports:
– “8090:8090”
depends_on:
configserver:
condition: service_healthy
environment:
SPRING_APPLICATION_NAME: “loans”
extends:
file: common-config.yaml
service: microservice-configserver-config
cards:
image: “dockerhub image name”
container_name: cards-ms
ports:
– “9000:9000”
depends_on:
configserver:
condition: service_healthy
environment:
SPRING_APPLICATION_NAME: “cards”
extends:
file: common-config.yaml
service: microservice-configserver-config
networks:
eazybank:
driver: “bridge”
common-config.yaml
services:
network-deploy-service:
networks:
– eazybank
microservice-base-config:
extends:
service: network-deploy-service
deploy:
resources:
limits:
memory: 700m
environment:
SPRING_RABBITMQ_HOST: “rabbit”
microservice-configserver-config:
extends:
service: microservice-base-config
environment:
SPRING_PROFILES_ACTIVE: default
SPRING_CONFIG_IMPORT: configserver:http://configserver:8071/
Tried to modify the networks attribute, but nothing worked