Portainer - how to expose the Caddyfile in a mount?

I am using Docker Compose in Portainer and want to use the Caddyfile (/etc/caddy/Caddyfile) in a persistent data volume I’ve created as:

    name: caddy_data
    external: true

I’ve tried this, but it doesn’t seem to see the Caddyfile.

      - caddy_data:/etc/caddy/Caddyfile 

What’s the best way to expose this Caddyfile so it can be backed up and edited even when the container image is updated?

That’s definitely wrong. You need the data mount to be /data to persist Caddy’s certs and keys. Config should not go in there.

I don’t really understand what you’re trying to do here. What’s the problem with mounting your Caddyfile normally? Keep Caddy Running — Caddy Documentation

I’m aware this is wrong. What I’m trying to do is mount the Caddyfile somewhere I can edit it and make it persist outside of the Caddy image.

      - /mnt/caddy/Caddyfile:/etc/caddy/Caddyfile

I am having trouble getting this to mount. I am runing Docker/Portainer in a VM, and using Docker Compose within Portainer. It isn’t able to access any of these mountpoints I’ve tried, but works fine with the /data folder being mapped to a persistent volume. I thought there was a way to also put the Caddyfile into that persistent storage volume so I can update it and it persists.

Where are you storing your docker-compose.yml file? Put your Caddyfile right next to that, then do - ./Caddyfile:/etc/caddy/Caddyfile

1 Like

I’ve tried that. Portainer itself keeps the docker-compose.yml files in its own folders (portainer/compose/###/). I’ve placed the Caddyfile there next to the docker-compose and it throws the same error.

container process: error during container init: error mounting "/data/compose/186/Caddyfile" to rootfs at "/etc/caddy/Caddyfile": mount /data/compose/186/Caddyfile:/etc/caddy/Caddyfile (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type 

Thanks for the assistance. I just got it to work using the following path:

- /var/lib/docker/volumes/caddy_data/_data/Caddyfile:/etc/caddy/Caddyfile

This places the file in the persistent volume as desired.

That’s really weird. You don’t need to put the file in a volume on the host. I’m confused.

1 Like

How would you handle this? Is there a better way?

As Keep Caddy Running — Caddy Documentation says, literally put the Caddyfile and docker-compose.yml files next to eachother. I’m not sure why that would be a problem. Both are config and should be treated as such. Config is not data, it doesn’t go in a data volume.

1 Like

This is probably the case outside of Portainer, but within Portainer paths are working differently. Please direct me to a working Portainer compose file for Caddy that addresses this if possible. I use data volumes for all sorts of purposes, and keeping some specific config files in them for a specific container makes some tasks simpler.