Dockerize backend, frontend, and database into separate containers

- backend/Dockerfile: multi-stage Python build (builder + slim runtime)
- frontend/Dockerfile: multi-stage Node build + nginx:alpine serving
- frontend/nginx.conf: SPA routing + /api/ reverse proxy to backend
- docker-compose.yml: production compose with health checks and proper dependency ordering
- docker-compose.dev.yml: dev overrides with hot reload via volume mounts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
curo1305
2026-04-12 15:22:04 +02:00
parent 85f76c70de
commit 114df7162f
7 changed files with 157 additions and 32 deletions
+28 -17
View File
@@ -1,35 +1,46 @@
services:
# ── Database ────────────────────────────────────────────────────────────────
db:
image: postgres:16
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: destroying_sap
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password}
POSTGRES_DB: ${POSTGRES_DB:-destroying_sap}
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
interval: 5s
timeout: 5s
retries: 10
# ── Backend (management) ────────────────────────────────────────────────────
backend:
build: ./backend
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
volumes:
- ./backend:/app
build:
context: ./backend
dockerfile: Dockerfile
restart: unless-stopped
env_file: ./backend/.env
environment:
DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-password}@db:5432/${POSTGRES_DB:-destroying_sap}
ports:
- "8000:8000"
environment:
DATABASE_URL: postgresql+asyncpg://postgres:password@db:5432/destroying_sap
depends_on:
- db
db:
condition: service_healthy
# ── Frontend (UI) ────────────────────────────────────────────────────────────
frontend:
build: ./frontend
command: npm run dev -- --host
volumes:
- ./frontend:/app
- /app/node_modules
build:
context: ./frontend
dockerfile: Dockerfile
restart: unless-stopped
ports:
- "5173:5173"
- "80:80"
depends_on:
- backend