Sign inSign up

fvillart/caddy-cloudflare

By fvillart

•Updated over 2 years ago

Caddy v2 with Cloudflare

Image
Web servers
0

1.7K

fvillart/caddy-cloudflare repository overview

⁠Based on:

https://registry.hub.docker.com/r/reverie89/caddy⁠

⁠Overview for Caddy v2

Based on official image, then added: caddy-dns/cloudflare module

Use the -security tag if you need additionally greenpau/security module

⁠Dockerfile

FROM caddy:2.7-builder AS builder
RUN xcaddy build \
    --with github.com/caddy-dns/cloudflare
FROM caddy:2.7
COPY --from=builder /usr/bin/caddy /usr/bin/caddy

⁠Usage

docker-compose.yaml

services:
  caddy:
    image: fvillart/caddy-cloudflare
    container_name: caddy
    restart: always
    environment:
      - CLOUDFLARE_API_TOKEN=xxx
    ports:
      - "80:80/tcp"
      - "443:443/tcp"
    volumes:
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./config:/config
      - ./data:/data
      - /var/www:/var/www

Caddyfile:

subdomain.example.com {
  tls {
    dns cloudflare {env.CLOUDFLARE_API_TOKEN}
  }

  reverse_proxy /* endpoint:80
}

example.com {
  tls {
    dns cloudflare {env.CLOUDFLARE_API_TOKEN}
  }

  root * /var/www/example.com
}

⁠Take note

Caddy v2 requires Cloudflare API token, not key. You will need to generate a token from your Cloudflare account if you don't have one.

Remember to mount /config and /data

Graceful Caddyfile reload: docker exec -w /etc/caddy {container_name} caddy reload

Format and overwrite Caddyfile: docker exec -w /etc/caddy {container_name} caddy fmt --overwrite

Tag summary

Content type

Image

Digest

sha256:4adafc87a…

Size

31 MB

Last updated

over 2 years ago

docker pull fvillart/caddy-cloudflare