Production-ready setup for Caddy v2 using Docker Compose. Features automatic HTTPS (Let's Encrypt), persistent storage, and a streamlined configuration workflow.
-
Clone the repository:
git clone https://github.com/uxname/caddy-caddy.git caddy cd caddy -
Prepare the configuration: Edit
./data/Caddyfileto define your domains and proxies. (SeeCaddyfile.exampleif available for reference). -
Make the utility executable:
chmod +x caddy.sh
-
Start the server:
docker compose up -d
We provide a specialized tool caddy.sh to manage configuration changes safely. It replaces manual formatting, validating, and reloading.
After editing your Caddyfile, simply run:
./caddy.shWhat this does (in order):
- Format: Auto-formats your Caddyfile (fixes indentation, braces).
- Validate: Checks configuration for syntax errors.
- Reload: Applies changes to the running server only if validation passes.
Note: If validation fails, the script stops immediately. Your running server will not be reloaded, preventing downtime caused by bad config.
If you need specific actions, you can run them individually:
| Command | Action |
|---|---|
./caddy.sh fmt |
Only formats the Caddyfile (overwrite). |
./caddy.sh validate |
Only checks the configuration syntax. |
./caddy.sh reload |
Reloads Caddy (use with caution, prefers apply). |
Since the script focuses on configuration, use standard Docker Compose commands for lifecycle management:
- Start:
docker compose up -d - Stop:
docker compose down - Logs:
docker compose logs -f caddy - Shell Access:
docker compose exec caddy sh
.
├── caddy.sh # Configuration management tool
├── docker-compose.yml # Container definition
└── data/
├── Caddyfile # Your main configuration
├── caddy_data/ # TLS certificates (auto-managed)
└── caddy_config/ # Internal Caddy state
- Always use
./caddy.shinstead of manually reloading via Docker. This ensures your config is always clean and valid. - Git Ignore: Ensure
data/caddy_dataanddata/caddy_configare added to your.gitignoreto avoid committing SSL certificates.