Unable to launch traefik with file provider without repeating full path inside configuration file

I have migrated to traefik 2.4 from traefik 1.7, and use the opportunity to switch from toml to yaml. Everything works, except that I can't figure out a way to simply launch traefik by giving it explicitly the file path such that it will correctly load everything in it. The only workaround I could find was to add a section like this:

    watch: true
    filename: C:\\etc\\traefik\\traefik.yaml

I don't particularly care for the dynamic file provider, as I generate the configuration and relaunch it when it changes. I really just want a single traefik.yaml file that can be moved around without necessarily editing it to change the file path, since I already explicitly pass it either as a command-line argument or environment variable.

I've been struggling for hours already trying to use either command-line parameters (--configfile, --providers.file, --providers.file.filename) or environment variables (TRAEFIK_PROVIDERS_FILE, TRAEFIK_PROVIDERS_FILE_FILENAME, etc). The closest I can get is to load the configuration file, but none of the entrypoints, routers, middlewares, servers get loaded.

I recall struggling a lot with the same issue in the old format, but only adding a "file" section was necessary in the 1.x toml format:


What is the proper way to make a simple static traefik.yaml file and tell traefik to use it? There's obviously something I don't understand.


in the v2, the dynamic configuration and the static configuration must be defined in separated files:

Ok, so my understanding is that traefik.yaml is supposed to be the static configuration file containing only the providers and the entry points? It's not very clear from the documentation what exactly should go in which configuration file, and if there is a naming convention for the dynamic configuration files:

Configuration in Traefik can refer to two different things:

* The fully dynamic routing configuration (referred to as the *dynamic configuration* )
* The startup configuration (referred to as the *static configuration* )

Elements in the *static configuration* set up connections to providers and define the entrypoints Traefik will listen to (these elements don't change often).

The *dynamic configuration* contains everything that defines how the requests are handled by your system. This configuration can change and is seamlessly hot-reloaded, without any request interruption or connection loss.

There is also a mention about the static file, command-line arguments and environment variables as being mutually exclusive, so my understanding is that I should pass everything I want statically with one of them, but never mix them. I split my file in two files (static.yaml, dynamic.yaml) and now have the following "static configuration file" that works, but I'm still stuck repeating the entire path to the corresponding dynamic configuration file:

  level: DEBUG
    watch: true
    filename: C:\etc\traefik\dynamic.yaml
    address: :4000

I noticed traefik on Linux appears to have better relative path handling with ".", but traefik on Windows doesn't. I run the same application within Linux and Windows containers, and I'm really looking for a way to make my configuration files relocatable and portable without having to modify or regenerate them. The fact that I have to explicitly pass the full path to the file breaks that, I am looking for a way to pass nothing but the path to the static configuration file, where the static configuration file can tell where to find the dynamic configuration file using a relative path.

Since traefik 1.x didn't enforce the static/dynamic separation, I didn't have this problem, and I could pass the full path to a single file once. How can I achieve the same using traefik 2.x? I really just want to tell traefik once where to read its configuration, using configuration files that are path independent.

I figured out a workaround, but it is not very practical: if I change the working directory for traefik to point to my traefik configuration directory, then I can use paths relative to this directory. The docs give a few places where traefik.yaml is searched by default, so I tried setting XDG_CONFIG_HOME on Windows in hope that maybe it would give me a similar behavior as changing the current working directory, but it didn't work (it was worth a try).

This means I can either make configuration files containing absolute paths to other files, making them harder to relocate on the filesystem, or I can make relocatable configuration files that only work if I change the traefik working directory. I guess we could modify the file loading behavior to look in a "TRAEFIK_HOME" path, but a quicker hack might be to accept a "TRAEFIK_WORKDIR" environment variable that gets picked up at startup to change the working directory. The main advantage is it would accept the workdir as a parameter, such that you don't need to launch the process with an explicit working directory.

The best long term solution might be a TRAEFIK_HOME parameter, and it would be very clear: I could just point it to a directory with all of the relocatable configuration files, and name the static one "traefik.yaml". However, TRAEFIK_WORKDIR would work as well and can be implemented much faster.

What do you think? A small tweak would go a long way to make configuration files easier to share and move around without having to edit the paths.

In the dynamic configuration, you can use sprig:

The main goal of Traefik is to manage dynamic architecture:

  • a container appears, Traefik detect it and create the configuration (based on labels)
  • a container disappears, Traefik detect it and remove the configuration

The file provider breaks this dynamic behavior.

The file provider, for the routing, has been introduced for only old architecture (VMs, bare metal servers, ...)

I never used the automatic features from traefik, even if I understand that this is what's being pushed. I generate the configuration automatically for my multi-container application and use it to expose 4-5 microservices externally from a single port, and it works well for both Windows and Linux containers. I still find it funny that you refer to this as "old architecture" :slight_smile:

I don't mind the split, it makes sense given the wide variety of providers that traefik supports. What I am looking for is a way to make the files "path independent" which makes them much easier to move around. Right now I can't launch traefik using the same configurations files in Linux and Windows containers without editing those paths. I literally test my application with both containers on Windows 10, just by switching the container platform.

Sprig templating looks like a no-go for the static configuration file:

Go Templating only works with dedicated dynamic configuration files. Templating does not work in the Traefik main static configuration file.

And even then, Sprig can pick up environment variables, but I'm not sure how I would express "relative to the static configuration file" or "relative to a TRAEFIK_HOME environment variable" because it doesn't exist. Surely there must be an acceptable tweak we can think of to solve this problem?