Can Caddy read env from an external configuration file(toml, json, yml, etc)

With my previous servers, I had a configuration file and this made my life easier using viper.
I am now migrating to Caddy and wondering if I could do the same thing without embedding caddy.
It would have values like hostname and port.
The point is to somehow get these values to the Caddyfile during start and to leave the Caddyfile alone after setup.

Hi @Ed_Siror,

Closest I can think of is to use the --envfile flag to load environmental variables and then then reference those variables in your Caddyfile: Caddyfile Concepts — Caddy Documentation

It wouldn’t be a structured configuration file though (like the examples in your post title), with that method it’d have to be a newline-delimited list of VARIABLE=VALUE entries.

This should work as long as it is an external file.
How do i specify --envfile in docker-compose.yml, or perhaps in the Caddyfile?

Isn’t this the same thing as simply providing a configuration file like usual? Caddy always reads its entire config from a file.

You can simply set environment variables on your docker-compose service and Caddy will inherit them:

Or otherwise, you’ll need to override and modity the command used to run the container and add the --envfile argument (needs to be a file that exists in the container):

1 Like

@francislavoie @matt, thanks for the clarification.
I thought this was something specific to only caddy and Caddyfile.
It is actually pretty simple and standard.

1 Like

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