Sitelet https://github.com/Gohar01/fastapi-docker-caddy-starter
Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI + Caddy + PostgreSQL Production Docker Starter

Docker FastAPI Python Caddy PostgreSQL Visual Configurator

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.


⚡ Architecture Overview

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
Loading

🚀 Quick Start (Under 60 Seconds)

1. Configure Environment Variables

Copy the example environment file:

cp .env.example .env

Edit .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=appdb

2. Build & Run Containers

docker compose up -d --build

Your FastAPI application will be accessible securely behind Caddy with automated HTTPS!

3. Verify Health

  • API Root: https://yourdomain.com/
  • Interactive API Docs (Swagger): https://yourdomain.com/docs
  • Healthcheck endpoint: https://yourdomain.com/healthz

🛡️ Production Features Included

  • 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-headers and --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.

📦 Taking this to Production? (Production Starter Pack)

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.yml that builds, tests, and deploys to your VPS over SSH on push to main.
  • 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.

🤝 Custom Stacks & Support

  • Free Online Configurator: DevOpsForge
  • MIT License — Free for commercial and personal use.

About

Production-grade FastAPI (Python 3.11) + Caddy (Auto-HTTPS) + PostgreSQL Docker Compose starter with non-root security

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages