Add Docker Compose setup with PostgreSQL 16 and Spring Boot app

Multi-stage Dockerfile for the backend (build + runtime).
Compose defines db (postgres:16-alpine with healthcheck) and app services.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-01 20:51:54 +02:00
commit c11d5ff192
2 changed files with 49 additions and 0 deletions

13
backend/Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
FROM eclipse-temurin:21-jdk-alpine AS build
WORKDIR /app
COPY mvnw pom.xml ./
COPY .mvn .mvn
RUN ./mvnw dependency:go-offline -B
COPY src src
RUN ./mvnw package -DskipTests -B
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

36
docker-compose.yml Normal file
View File

@@ -0,0 +1,36 @@
services:
db:
image: postgres:16-alpine
container_name: mealprep-db
environment:
POSTGRES_DB: mealprep
POSTGRES_USER: mealprep
POSTGRES_PASSWORD: mealprep
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U mealprep"]
interval: 5s
timeout: 3s
retries: 5
app:
build:
context: ./backend
dockerfile: Dockerfile
container_name: mealprep-app
ports:
- "8080:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/mealprep
SPRING_DATASOURCE_USERNAME: mealprep
SPRING_DATASOURCE_PASSWORD: mealprep
SPRING_PROFILES_ACTIVE: docker
depends_on:
db:
condition: service_healthy
volumes:
pgdata: