A production-grade, hardened Docker Compose boilerplate for FastAPI (Python 3.11 + Uvicorn) served behind a Caddy reverse proxy with automated Let's Encrypt SSL/TLS, HTTP/3 QUIC support, and PostgreSQL 16.
💡 Need a different backend, Redis cache, or Nginx?
Customize your stack visually with our free client-side tool: DevOpsForge Web Configurator.
flowchart LR
Client([Public Traffic]) -->|Port 80 / 443 HTTPS| Caddy[Caddy Reverse Proxy\nAuto-TLS + HTTP/3]
subgraph Internal Bridge Network
Caddy -->|Uvicorn Port 8000| FastAPI[FastAPI App\nPython 3.11-slim]
FastAPI -->|Internal DNS :5432| Postgres[(PostgreSQL 16)]
end
Copy the example environment file:
cp .env.example .envEdit .env to set your public domain name and database credentials:
APP_DOMAIN=yourdomain.com
ACME_EMAIL=your-email@domain.com
POSTGRES_USER=appuser
POSTGRES_PASSWORD=your_secure_password
POSTGRES_DB=appdbdocker compose up -d --buildYour FastAPI application will be accessible securely behind Caddy with automated HTTPS!
- API Root:
https://yourdomain.com/ - Interactive API Docs (Swagger):
https://yourdomain.com/docs - Healthcheck endpoint:
https://yourdomain.com/healthz
- Multi-Stage Docker Build: Separates heavy compilation wheels from the final minimal runtime image.
- Non-Root Security: Runs under an isolated unprivileged user (
appuser:appgroup, UID/GID 1001). - Automated TLS & HTTP/3: Caddy handles certificate creation and renewals automatically.
- Forwarded Proxy Headers: Pre-configured with
--proxy-headersand--forwarded-allow-ips=*to ensure accurate client IP detection and SSL redirection behind reverse proxies. - Docker Compose Health Checks: Both FastAPI (
/healthz) and PostgreSQL (pg_isready) have native health checks with automatic restart policies.
If you are deploying this stack to a cloud VPS (Hetzner, DigitalOcean, AWS, Linode) and need automated CI/CD and backups:
👉 Get the Full Production Starter Pack ($19)
The $19 pack includes:
- Zero-Downtime GitHub Actions CI/CD: Complete
.github/workflows/deploy.ymlthat builds, tests, and deploys to your VPS over SSH on push tomain. - Automated S3/R2 Cloud Backups: Daily encrypted database dump script with rotation and Discord/Slack webhook notifications.
- Hardened Nginx & Caddy Templates: Rate-limiting, DDoS mitigation buffers, and HSTS preloading.
- All 5 Framework Stacks: Ready-to-go templates for Next.js, FastAPI, Laravel, Spring Boot, and Django.
- Free Online Configurator: DevOpsForge
- MIT License — Free for commercial and personal use.