Caddy2 cloudflare plugin

How to use cloudflare with caddy2?

Hi @Dejan_Milosevic,

Caddy v2 doesn’t have a slick custom build download page, so you’d have to compile it manually with the Cloudflare DNS module included.

See the DNS modules’ Github page for more info and instructions:

Where I can find documentation about how to do that?


The Github link I provided outlines how to go about it.

First plug in your desired provider module and then configure the DNS challenge in your Caddy JSON, for example:

	"challenges": {
		"dns": {
			"provider": "cloudflare",
			"api_token": "secret"

So as module i use or some other link?

@Dejan_Milosevic I wrote a step-by-step tutorial on how to compile Caddy v2 with Cloudflare plugin here :point_down: (replace @v2.0.0-beta.14 with @v2.0.0-beta.15)


Compiling caddy with custom modules using docker.

docker run --rm -v `pwd`/output:/output caddy:builder sh -c "caddy-builder && cp /usr/bin/caddy /output/"

No need to checkout source or install go.


Is there any way we could get that to work in a docker compose file?

Yep, take a look at the docs on Docker Hub: Docker Hub

Look for the “Adding custom Caddy modules” section. Just make a Dockerfile, add the plugins you want to it, then build from that Dockerfile.

Thanks for this! Somewhat new to Dockerfiles and have never used them before. I generally just follow self hosted tutorials and it’s all done via Docker Compose. What I don’t understand is that how does docker compose know to use the image from the Dockerfile?


Docker file:

FROM caddy:2.0.0-builder AS builder

RUN caddy-builder \

FROM caddy:2.0.0

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

Compose file:

version: "3"

    container_name: caddy
    build: .
      - 80:80
      - 443:443
      - /home/docker/caddy/Caddyfile:/etc/caddy/Caddyfile
      - /home/docker/caddy/data:/data
      - /home/docker/caddy/config:/config

Is the build: . directive enough for Docker Compose to know which image to use?

A build: line tells Compose to build a container based on the context you set, in exactly the same manner as the docker build command (probably because it effectively is the docker build command).

. is a reference to the current directory, so - assuming docker-compose.yml and Dockerfile are in the same directory and you kick off the build from there, yes, it should work.

Basically just send docker-compose build caddy and you should be off to the races.


That’s for v1, which is no longer being developed.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.