AS
Ashish-bbg/springboot-postgres-docker-template
Spring Boot + PostgreSQL + Docker starter template
Spring Boot + Docker + PostgreSQL Template
A reusable starter template for Spring Boot applications with Docker and PostgreSQL.
This template includes:
- Multi-stage Docker build for optimized images
- PostgreSQL container with persistent volume
- Environment-based DB configuration
- Ready-to-run Spring Boot app
Prerequisites
- Java 17 or 21
- Maven
- Docker & Docker Compose
Getting Started
# Clone this template
git clone https://github.com/YOUR_USERNAME/springboot-docker-template my-new-app
cd my-new-appRename Your Project
- Update
artifactIdinpom.xml. - Update
spring.application.nameinsrc/main/resources/application.properties. - Update the database name or credentials in
docker-compose.ymlif needed.
Build & Run
# Build the Spring Boot app
mvn clean package -DskipTests
# Start containers
docker compose up --buildThe app will be available at:
http://localhost:4000
Stop Containers
# Stop containers (keep DB data)
docker compose down
# Stop containers & remove volumes (reset DB)
docker compose down -vNotes
- Uses Java 21
- Uses PostgreSQL 15
- Multi-stage Docker build ensures smaller images
- Database configuration is environment variable-based
- Spring Boot app depends on the database container
✅ Optional improvements you could consider:
- Health check for Postgres to ensure the app waits until DB is ready
- Switch DB easily using environment variables for MySQL/Postgres without editing the file
On this page
Languages
Dockerfile100.0%
Contributors
Apache License 2.0
Created January 22, 2026
Updated January 22, 2026