Developer Guide · 14

Docker Deployment

14.1 Multi-stage Build

dockerfile
# Stage 1: frontend-builder
FROM node:20-alpine AS frontend-builder
RUN npm ci && npm run build       # → dist/

# Stage 2: production
FROM python:3.11-slim
RUN pip install -r requirements.txt
RUN npm install express http-proxy-middleware
COPY --from=frontend-builder /build/dist /app/frontend/dist
  • React source and devDependencies not included in final image
  • Express server.js serves static files from dist/

14.2 docker-compose

text
Cloudflare (SSL) → Nginx (:80) → Express (:3000) → FastAPI (:8000)
  • Nginx: SSL termination + reverse proxy (nginx/nginx.conf)
  • Express: static files + /api proxy
  • FastAPI: core backend
  • User data volume: ./data/users:/app/users

14.3 Startup Script (start.sh)

  1. Start FastAPI (:8000)
  2. Wait until ready, then start Express (:3000)
  3. wait -n monitors both processes

14.4 Health Check

Container has built-in health check (checks FastAPI /docs endpoint). Nginx only accepts traffic after backend is ready.

14.5 .dockerignore

Excludes frontend/node_modules/ / frontend/dist/ / venv/ / data/ / .env / .git/.