Docker Compose for Spring Boot + PostgreSQL
A Java Spring Boot application with PostgreSQL. Enterprise-grade backend stack.
java spring postgres backend enterprise
compose.yaml
services:
app:
build: .
ports:
- target: 8080
mode: ingress
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/springboot
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=${SPRING_DATASOURCE_PASSWORD}
- SPRING_PROFILES_ACTIVE=production
healthcheck:
test:
- CMD
- curl
- -f
- http://localhost:8080/
interval: 30s
timeout: 5s
retries: 3
depends_on:
- db
deploy:
resources:
reservations:
cpus: "1"
memory: 512M
restart: unless-stopped
db:
image: postgres:16
ports:
- target: 5432
mode: host
environment:
- POSTGRES_DB=springboot
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
healthcheck:
test:
- CMD-SHELL
- pg_isready -U postgres
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
reservations:
cpus: "0.5"
memory: 256M
restart: unless-stopped
x-defang-postgres: true
Services
- app .
- db postgres:16