Installing Caddyv2 with Cloudflare Plugin on NAS

1. Caddy version (caddy version):

Caddy v2.1.1

2. How I run Caddy:

Docker on Synology NAS

a. System environment:

Xpenology DS3615XS

3. The problem I’m having:

I cant find a good Docker tutorial for use with a synology NAS. Could someone link me or explain how to run caddy on docker on a synology Nas with the cloudflare plugin. I am using a caddyfile i have already used in the past with another linux install. I just cant find out how to install Caddyv2 with cloudflare plugin on a synology NAS on docker.

Sorry for such a generic questions. Ive never really used docker until building this NAS.

The recommended way to build Caddy with plugins in Docker is by using the builder image variant. Instructions are here:

You can find a list of the available plugins here:

I highly recommend using v2.2, there’s plenty of great fixes and improvements.

So if i did run it through docker. I apologize im still not very familiar with manually running docker on ssh. But im assuming i run my nas ip ie : 192.168.1.59 on putty. then login with root access or my regular user which has admin rights in putty ssh terminal. Then i run the command alone.


RUN xcaddy build \
    --with github.com/caddyserver/nginx-adapter \
    --with github.com/caddy-dns/cloudflare \

FROM caddy:2.2.0

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

Do i need to change above to v2.2? Thank you ahead i really appreciate the help. also how do i implement my already pre-made caddyfile where would it go? Also i dont quite understand the building commands could i get an example of what exactly i have to type in my synology nas ssh to make it build such as docker run ****** Thank you again

That’s a Dockerfile, not linux commands. A Dockerfile describes how to build a docker image, from which you can spawn containers.

You’re also missing the first line with FROM caddy:2.2.0-builder AS builder (and yes, replace <version> with the current version, i.e. 2.2.0). I don’t think you’ll need the nginx-adapter plugin, so you can remove that. Also, make sure that there’s no trailing \ there, that means “escape the newline”, so it might consider the following FROM as part of that RUN command. It’s necessary to split up the command onto multiple lines, but there shouldn’t be one on the last line of that command.

If I’m understanding correctly (never used Synology), you’ll need to ssh in, make a new file somewhere called Dockerfile, then run docker build -t caddy-with-cloudflare . which will build you a container tagged with caddy-with-cloudflare which you can then use later.

The rest is as before, just use docker run (I guess? I don’t know how Synology manages docker stuff, does it have an interface for that?) but instead use your new caddy-with-cloudflare image instead of caddy which is the vanilla image.

i apologize i made a new directory in the main admin users ssh by writing sudo mkdir caddy then cd /caddy/ doing sudo touch Dockerfile then sudo nano Dockerfile i added in the the lines below to that Dockerfile. `FROM caddy:V2.2.0-builder AS builder

    --with github.com/caddy-dns/cloudflare

FROM caddy:v2.2.0

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

Then CTRL+O and CTRL+X to save and exit the file. in the same directory. i typed docker build -t caddy-with-cloudflare but i get a return error with this

"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

any idea what i may have done wrong.

update #2. I got it to succesfully run by sending sudo docker build -t caddy-with-cloudflare - < Dockerfile in ssh. then it correctly built the image i hope. Now where do i put my pre-made Caddyfile

The . in the command I mentioned is important, it means “look in the current directory”.

$ docker build -t caddy-with-cloudflare .

You can load your Caddyfile into the container using a volume, as described in the docs

This is my docker-compose.yml ive made before. it works but it looks different than the example you guys gave.

version: "3.5"

services:

  caddy:
    container_name: caddy
    build:
      context: caddy
      network: host
    environment:
      CLOUDFLARE_EMAIL: 'email@hotmail.com' #Replace with your email.
      CLOUDFLARE_API_TOKEN: 'api key' #Replace>
    ports:
      - "443:443/tcp"
    volumes:
      - './Caddyfile:/etc/caddy/Caddyfile'
      - './html:/usr/share/caddy'
    restart: always

how do i add a volume on my local nas directory. ie
the apps folder is /volume1/apps/Caddy
the config folder is /volume1/apps/config/Caddy

but where i ran the command sudo docker build -t caddy-with-cloudflare - < Dockerfile it was in the root of the system i cant find where the folder is located. Any ideas

If you’re using docker-compose, that simplifies things. You can use a service definition like this instead:

services:
  caddy:
    build:
      context: caddy
    restart: unless-stopped
    environment:
      CLOUDFLARE_API_TOKEN: 'api key'
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - $PWD/html:/srv
      - caddy_data:/data
      - caddy_config:/config

Just replace the Dockerfile you were using before in the build context with your new one that uses the builder image (you won’t need to care about the docker build command anymore if you’re using docker-compose because it will build for you if necessary).

In your Caddyfile, you can reference the API token with {env.CLOUDFLARE_API_TOKEN} when configuring the DNS challenge.

Do you mean where the context options is below the build: do i link the file that i used to build ie. cd /caddy/Dockerfile or am i listing the one i already built off that dockerfile tagged as caddy-with-cloudflare. Also will where will i insert my pre-made Caddyfile.
I was going to use this script if its incorrect please point out what exactly needs to change thank you.

  caddy:
    build:
      context: caddy-with-cloudflare
    restart: unless-stopped
    environment:
      CLOUDFLARE_API_TOKEN: 'api key'
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - $PWD/html:/srv
      - caddy_data:/data
      - caddy_config:/config 

also what do i run to execute the docker-compose.yml

context is a directory in which a Dockerfile is expected to exist.

If your Dockerfile is in a dir called caddy-with-cloudflare, then you’re good to go.

There’s nothing special about the name caddy-with-cloudflare, it’s just a tag I came up with earlier to clearly indicate what the build image contains. But that’s not necessary at all if you’re using docker-compose.

At this point, I think you just need to do some reading of Docker documentation and guides, I can’t really be spending the time teaching you all the intricacies on a forum thread, it’s not really worth my time to rehash information that exists elsewhere.

i undestand thank you for all the help ive been reading up on docker-compose since my last message. i have one more question. I think ive ironed out everything else but this one error im still getting i think it has to do with the docker-compose.yml when i run docker-compose up -d i get this error

ERROR: Named volume "caddy_data:/caddy/data:rw" is used in service "caddy" but  no declaration was found in the volumes section.

I think it has something to do with these two lines in my docker compose volume section

     - caddy_data:/caddy/data
     - caddy_config:/caddy/config

Could you tell me what these are used for and why they would be spitting out that error? Again thank you ahead of time.

It’s /data and /config

Okay could you explain why or what the error means that i get when i run docker-compose up -d

ERROR: Named volume "caddy_data:/data:rw" is used in service "caddy" but no declaration was found in the volumes section.

At the very bottom of your docker-compose.yml, add:

volumes:
  caddy_data:
  caddy_config:

Again i understand where it is located and that it is in my docker-compose.yml. But i dont undestand why i am getting this error.

This topic was automatically closed after 30 days. New replies are no longer allowed.