I'm usiing docker-compose to containerize my rest api. One service for my spring app et the other for the database. The probleme is the spring boot api try to connect by default to the database by using localhost but since it is the container it create an error ( Connection to localhost:5432 refused. Check that the hostname and port). And the container stop working since the app don't work. How to tell to my spring boot api to try to conect to the database container.
version: "3"
services:
app_service:
container_name: app_service
build: .
ports:
- "8080:8080"
depends_on:
- postgresql
networks:
- net
postgresql:
image: postgres:15.0
container_name: db
ports:
- "5432:5432"
restart: unless-stopped
environment:
POSTGRES_PASSWORD : Access/fedora/6
POSTGRES_DB : postgres
volumes:
- psql:/var/lib/postgres/psql
networks:
- net
volumes:
psql:
networks:
net:
cloud:
aws:
credentials:
secret-key: 'qdfqdfqsdfqsdqsdfqsdfqs'
access-key: 'qfqsdfqserfqegdrhfjkgkh'
region:
static: eu-west-3
stack:
auto: 'false'
spring:
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: 'true'
show-sql: 'true'
hibernate:
ddl-auto: update
servlet:
multipart:
max-file-size: 5MB
enabled: 'true'
max-request-size: 10MB
file-size-threshold: 2MB
datasource:
hikari:
jdbc-url: jdbc:postgresql://db:5432/postgres
password: Access/fedora/6
application:
bucket:
name: moood-app
I tried to search if there was a image of a spring project that I could use but i did'nt find one that can help me. I tried to find a way to set a default jdbc url for the spring container but didn't find it.
I hope to find a way to set the connexion between the containers