I am running Spring Boot 3.3. and Docker. I my app can successfully access the Postgres database using the config below.
Question
How can I configure this so that the I can access the Posrgres database from outside the Docker Container?
My DBeaver client can connect, but I cannot seem to query the table in the database, using the following url:
jdbc:postgresql://localhost:5431/expiry_service_db
docker-compose.yml
version: '1.0'
services:
app:
image: 'docker-spring-boot-postgres:latest'
build:
context: .
dockerfile: Dockerfile
container_name: app
ports:
- "8081:8080"
#network_mode: host
depends_on:
- db
environment:
- SPRING_PROFILES_ACTIVE=dev
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/expiry_service_db
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=postgres
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
db:
image: postgres:latest
container_name: db
restart: always
environment:
- POSTGRES_DB=expiry_service_db
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
ports:
- "5431:5432"
#network_mode: host
volumes:
- postgres_data:/var/lib/postgresql
volumes:
postgres_data: