Caddy with docker label support & Cloudflare
This image will inspect container labels & translate them into a caddy config like so:
services:
server:
...
networks:
- proxy_network
deploy:
labels:
# *.example.com {
- caddy: '*.example.com'
# revere_proxy <DOCKER IP>:80
- caddy.reverse_proxy: {{upstreams 80}}
# tls { dns cloudflare }
- caddy.tls.dns: cloudflare
# }Other useful patterns:
# Load-balance sockets
caddy.reverse_proxy.lb_policy: client_ip_hash
# Multiple domains
caddy: a.example.com b.example.com
caddy.@match0.host: a.example.com
caddy.@match1.host: b.example.com
caddy.0_reverse_proxy: '@match0 {{upstreams 80}}'
caddy.1_reverse_proxy: '@match1 {{upstreams 81}}'
# Whitelist network
caddy.@local.remote_ip: '192.168.0.0/24'
caddy.handle: '@local'
caddy.handle.reverse_proxy: '{{upstreams 3000}}'See caddy-docker-proxy for more information
- Create a compose file:
services:
caddy:
image: cpritchett/caddy-labels:latest
environment:
CADDY_INGRESS_NETWORKS: proxy_network
TZ: America/Toronto
ports:
- 80:80
- 443:443
volumes:
- data:/data/caddy
- /var/run/docker.sock:/var/run/docker.sock
networks:
- proxy_network
deploy:
mode: global
labels:
caddy.email: example@example.com
# Cloudflare
caddy.acme_dns: 'cloudflare TOKEN'
networks:
proxy_network:
volumes:
data:- Deploy:
docker compose up
- Update desired version number in Dockerfile
- Build docker image:
docker build -t cpritchett/caddy-labels:latest .
This project includes comprehensive linting for code quality:
Setup with mise (recommended):
mise run setup # Install all tools and dependenciesSetup without mise:
bun install # Install Bun dependencies
# Install hadolint manually for your platformAvailable commands:
bun run lint # Run all linters
bun run lint:docker # Lint Dockerfile with hadolint
bun run lint:markdown # Lint Markdown files
bun run lint:yaml # Lint YAML files with ESLint
bun run lint:fix # Auto-fix Markdown issuesTools included:
- Bun - Fast JavaScript runtime and package manager
- Socket.dev - Dependency security scanning (GitHub Actions)
- Hadolint - Dockerfile linting and security checks
- markdownlint - Markdown formatting and style
- eslint-plugin-yml - YAML syntax and style via ESLint
- commitlint - Conventional commit message format
- Husky - Git hooks for pre-commit linting
Git hooks:
- Pre-commit: Runs all linters before allowing commits
- Commit-msg: Validates commit message format
This project uses Release Please for automated versioning and release management based on Conventional Commits.
Versioning Strategy: This project uses independent semantic versioning (e.g., v1.0.0,
v1.1.0) to track changes to this wrapper repository. The Caddy version in each release is
clearly identified via the caddy-X.Y.Z Docker tag.
Docker images are tagged with multiple formats:
- Semantic Version Tags:
1.0.0,1.0,1(track wrapper repository changes) - Caddy Version Tag:
caddy-2.10.0(shows the Caddy version included) - Latest Tag:
latest(always points to the most recent main branch build) - Timestamp Tag:
YYYYMMDD-HHmmss(for each main branch build)
- For Caddy Updates: Renovate detects new Caddy versions and creates a PR
- Merge with Conventional Commit: Use appropriate commit format (e.g.,
fix: upgrade to Caddy 2.11.0) - For Wrapper Changes: Make changes with conventional commits (feat:, fix:, docs:, ci:)
- Release Please Triggers: Automatically creates/updates a release PR with:
- Automated CHANGELOG updates (including all changes since last release)
- Version bump based on conventional commits
- Merge Release PR: Creates a GitHub release and triggers Docker image builds
v1.0.0- Initial release (Caddy 2.10.0)v1.1.0- Add new plugin support (still Caddy 2.10.0)v1.2.0- Upgrade to Caddy 2.11.0v1.2.1- Fix configuration bug (still Caddy 2.11.0)
Follow the Conventional Commits specification:
feat:- New features (bumps minor version)fix:- Bug fixes or Caddy upgrades (bumps patch version)docs:- Documentation changes (included in changelog)ci:- CI/CD changes (included in changelog)chore:- Maintenance tasks (hidden from changelog)- Add
!orBREAKING CHANGE:for breaking changes (bumps major version)
Examples:
fix: upgrade to Caddy 2.11.0 for security patchesfeat: add support for Tailscale pluginci: improve Docker build caching
Copyright © 2023 cpritchett | Available under MIT Licensing
See the license for more information.