Skip to content

plantedbrain/springboot-postgres-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot + PostgreSQL (Local & Docker) Demo

This project is a simple Spring Boot REST API connected to a PostgreSQL database.
It showcases a clean starter setup using:

  • Spring Boot
  • PostgreSQL
  • Spring Data JPA
  • Docker + docker-compose
  • DBeaver / pgAdmin (optional for database UI)

🚀 Features

  • REST API for Employee CRUD
  • Automatic table creation using Hibernate
  • Local PostgreSQL setup
  • Optional Docker-based PostgreSQL setup
  • Production-ready folder structure

📌 1. Local PostgreSQL Setup (Without Docker)

1. Install PostgreSQL

Download from:
https://www.postgresql.org/download/

During installation:

  • Set username: postgres
  • Set password: (choose your password)
  • Install pgAdmin (optional)

2. Create your database

Open pgAdmin → Query Tool:

CREATE DATABASE demo_db;

🐳 PostgreSQL Setup Using Docker

This section explains how to run PostgreSQL locally using Docker with a simple docker-compose.yml setup.
This approach avoids manual installation and makes your database environment easy to reset or version.

📌 1. Prerequisites

Install:

Docker Desktop

Download: https://www.docker.com/products/docker-desktop/

Ensure Docker is running before executing commands.


📌 2. Create docker-compose.yml

Create a folder (example):

C:\postgres-docker

Inside it, create this file:

### **docker-compose.yml**

```yaml
version: '3.8'

services:
  postgres:
    image: postgres:15
    container_name: postgres_local
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: admin123
      POSTGRES_DB: demo_db
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:

📌 3. Start PostgreSQL Using Docker

Run inside the folder containing docker-compose.yml:

docker compose up -d

Verify the container:

docker ps

Expected:

postgres_local  Up  0.0.0.0:5432->5432/tcp
Screenshot 2025-12-02 144800

🔧 Useful Docker Commands

Stop containers

docker compose down

Remove containers & volume (wipe database)

docker compose down -v

View logs

docker logs postgres_local

Restart PostgreSQL

docker restart postgres_local

About

This project is a simple Spring Boot REST API connected to a PostgreSQL database.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages