Sign inSign up

zachbg/caddy-cloudflare

By zachbg

•Updated 6 months ago

Caddy 2 with Cloudflare DNS, DuckDNS, and security plugins for auto HTTPS

Image
1

10K+

zachbg/caddy-cloudflare repository overview

⁠caddy-cloudflare

Caddy web server with Cloudflare DNS plugin — automatic HTTPS with wildcard certs, even behind NAT.

Docker Image Docker Pulls

⁠Why?

The official Caddy image doesn't include the Cloudflare DNS plugin. This image adds:

  • Cloudflare DNS-01 challenge — HTTPS behind firewalls, NAT, Docker networks
  • Wildcard certificates — *.yourdomain.com with one config
  • DuckDNS plugin — free dynamic DNS alternative
  • Security plugin — authentication portal built-in
  • Transform encoder — structured/JSON access logs

⁠Quick Start

docker run -d \
  --name caddy \
  -p 80:80 -p 443:443 \
  -e CLOUDFLARE_API_TOKEN=your-token-here \
  -v ./Caddyfile:/etc/caddy/Caddyfile \
  -v caddy-data:/data \
  -v caddy-config:/config \
  zachbg/caddy-cloudflare

⁠Docker Compose

services:
  caddy:
    image: zachbg/caddy-cloudflare
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"  # HTTP/3
    environment:
      - CLOUDFLARE_API_TOKEN=${CLOUDFLARE_API_TOKEN}
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy-data:/data
      - caddy-config:/config

volumes:
  caddy-data:
  caddy-config:

⁠Cloudflare API Token

  1. Go to Cloudflare Dashboard → API Tokens⁠
  2. Create a token with:
    • Zone / Zone / Read
    • Zone / DNS / Edit
  3. Set as CLOUDFLARE_API_TOKEN environment variable

⁠Caddyfile Examples

⁠Wildcard Reverse Proxy
*.home.example.com {
    tls {
        dns cloudflare {env.CLOUDFLARE_API_TOKEN}
    }

    @jellyfin host jellyfin.home.example.com
    handle @jellyfin {
        reverse_proxy jellyfin:8096
    }

    @nextcloud host cloud.home.example.com
    handle @nextcloud {
        reverse_proxy nextcloud:80
    }
}
⁠Simple Reverse Proxy
app.example.com {
    tls {
        dns cloudflare {env.CLOUDFLARE_API_TOKEN}
    }
    reverse_proxy app:3000
}

⁠Included Plugins

PluginPurpose
caddy-dns/cloudflareCloudflare DNS-01 ACME challenge
caddy-dns/duckdnsDuckDNS DNS-01 ACME challenge
caddy-securityAuthentication portal (SSO, OAuth, etc.)
transform-encoderStructured/JSON access logs

⁠Multi-arch

docker buildx build --platform linux/amd64,linux/arm64 -t zachbg/caddy-cloudflare --push .

⁠License

MIT

Tag summary

Content type

Image

Digest

sha256:6307ee4cd…

Size

45.3 MB

Last updated

6 months ago

docker pull zachbg/caddy-cloudflare