A lightweight, automated, and production-ready reverse proxy setup using Caddy with Docker, featuring:
- ✅ Automatic SSL via Cloudflare DNS
- ✅ Dynamic reverse proxy via Docker labels
- ✅ No manual Caddyfile needed
- ✅ FastAPI backend with auto-reload support
- ✅ Unified control with Makefile
- ✨ Features
- 📋 Prerequisites
- 🚀 Quick Start
- 📦 Installation
- 🛠️ Usage (Makefile)
- 📜 Logs
- ⚙️ Configuration
- 🔧 Optional Enhancements
- ℹ️ Notes
- 🔐 Automatic HTTPS with Cloudflare DNS
- 🐳 Dockerized FastAPI microservice
- 🔄 Auto-reload during development
- ⚙️ Declarative service routing via Docker labels
- 🧼 Clean, one-file
Makefileinterface - 🧪 Ready for testing and CI workflows
- ✅ Docker & Docker Compose
- ✅ Cloudflare-managed domain
- ✅ Cloudflare API Token with DNS edit permission
-
Clone repo & navigate:
git clone https://your-repo-url cd your-repo -
Create a Docker network (once):
docker network create web || true
-
Add your
.envfile:CLOUDFLARE_API_TOKEN=your_cloudflare_token_here DOMAIN=example.com EMAIL=[email protected]
-
Start everything:
make up
You can also use the provided installation script:
chmod +x install.sh
./install.shThe script will:
- Scaffold your project
- Download Docker images
- Configure FastAPI app
- Set up Caddy reverse proxy
- Start services
Unified CLI control with:
make up # Build and run all containers
make down # Stop containers
make restart # Restart containers
make logs # Show combined logs (API + Caddy)
make logs-api # Show only API logs
make logs-caddy # Show only Caddy logs
make shell # Open shell in the API container
make clean # Remove all containers, volumes, and dangling images
make health # Check public HTTP health of the serviceYou can also use these commands:
make lint # Run linter (flake8)
make test # Run tests (pytest)
make deploy # (alias for up, or hook for real deploy)✅ These run inside temporary containers – you don't need local Python installed.
# Combined logs
make logs
# Individual service logs
make logs-api
make logs-caddy.envfile for secrets (required):
CLOUDFLARE_API_TOKEN=your_cloudflare_token
EMAIL=[email protected]
DOMAIN=example.com- Routing is defined via labels in
docker-compose.yml:
labels:
caddy: api.${DOMAIN}
caddy.reverse_proxy: "{{upstreams 8080}}"
caddy.tls.dns: "cloudflare {env.CLOUDFLARE_API_TOKEN}"No need to manually write a Caddyfile — Caddy dynamically reads this.
Makefile includes:
make lint # Runs flake8 on your Python code
make test # Runs pytest inside containerFastAPI auto-reload enabled via:
command: uvicorn app.main:app --host 0.0.0.0 --port 8080 --reload
volumes:
- ./app:/app/app:roSupport multiple services using:
make logs SERVICE=auth
make shell SERVICE=webMakefile dynamically uses $(SERVICE) to manage different containers.
- Uses
lucaslorentz/caddy-docker-proxyfor dynamic reverse proxy configuration. - All SSL certificates are auto-managed via Cloudflare DNS.
- Works well on ARM (Raspberry Pi), VPS, and dev machines.
- Recommended for small production deployments with minimal overhead.