GitHunt
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-app

Rename Your Project

  1. Update artifactId in pom.xml.
  2. Update spring.application.name in src/main/resources/application.properties.
  3. Update the database name or credentials in docker-compose.yml if needed.

Build & Run

# Build the Spring Boot app
mvn clean package -DskipTests

# Start containers
docker compose up --build

The 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 -v

Notes

  • 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

Languages

Dockerfile100.0%

Contributors

Apache License 2.0
Created January 22, 2026
Updated January 22, 2026