I have Spring Boot 3 and Docker.
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
- POSTGRES_DB=expiry_service_db
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
ports:
- "5432:5432"
#network_mode: host
volumes:
- postgres_data:/var/lib/postgresql
volumes:
postgres_data:
My application can successfully connect to my database (within the container).
Question
How do I configure it to allow a SQL client (e.g. DBeaver) to also connect to the postgres database (outside the container)?
The url is defined above as:
jdbc:postgresql://db:5432/expiry_service_db
So I guess I need to somehow map db
in the url to localhost
, and then connect the SQL Client via:
jdbc:postgresql://localhost:5432/expiry_service_db