Container-specific config files? (Ditching labels for config files)

I recently had to implement a file provider (as explained here) in order to get a custom certificate to work on my local development machine.

I now prefer using config files over container labels, since config files are much more readable due to their inherent visual hierarchy and having less redundant text. (For config values in labels, each value must be preceded by its entire hierarchy/path in "flat" dot notation, making it excessively verbose and harder to read/understand.)

So my question is, what's the best way to implement container-specific configurations - such as for "dev" and "live" - using config files?

With labels, I simply leveraged Docker's built-in override feature for compose files. It's not clear how to achieve the same thing using Traefik config files.

Any info or insights appreciated!

One thing you can do natively in traefik is utilise Go Templating but this does not work in the static config file.

This will allow the use of an environment variables for your config.

Otherwise you're stuck with docker/git magics.

Thanks for the reply, @cakiwi. Something else occurred to me. Perhaps you can tell me if you think this would work...

What if I continued to use the Docker compose file override mechanism, but instead of using labels, I just bind-mounted the appropriate config file in the volumes section of each container. If the file provider is configured to monitor a directory, then Traefik should see only the config files corresponding to running containers, right?

I haven't tried it, but is my understanding correct?

Yep, that is completely rational. I've done it myself.

I use the Go Templates to proxy non-docker services, I prefer it as it is reusable vs wrangling a bunch of files/directories.

Also if you are expecting the file providers to be fully dynamic in docker(update the file and it is reloaded by traefik), they not(or at least I have not got it to work). As far as I can tell "its a docker thing" as to how it bind mounts.

1 Like

Yeah, this is a real issue with Traefik. I can't even come up with a Docker or Compose strategy for having different startup configs without simply replicating a bunch of info across files. Most of the static config is the same between dev and live, but I can't come up with a way to add only the different/changed information without resorting to some "external" means.

I don't understand why this limitation exists, but it's a real bummer. :frowning_face:

If anyone has any ideas, I'm all :ear:'s