Skip to main content

Traefik file provider configuration

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

In Traefik providers are infrastructure components (e.g. container engines, cloud providers, or key-value stores) that can be queried in order to find relevant information about the routing configuration.

For static, global services it can make sense to define the service in a file. All you have to do in your global Traefik configuration file is reference that other file:

[providers]
[providers.file]
directory = "/"
filename = "static_services.toml"

However, there's no need for a separate file. You can also define those services in your global Traefik configuration:

[entryPoints]
[entryPoints.traefik]
address = ":8080"
[entryPoints.traefik.http.tls]
certResolver = "myresolver"

[http]
[http.routers]
[http.routers.metrics]
rule = "Host(`somehost.loc`) && PathPrefix(`/metrics`)"
entryPoints = ["traefik"]
service = "prometheus@internal"
middlewares = ["metrics-auth"]

[metrics]
[metrics.prometheus]
manualRouting = true

When I first tried it like that, Traefik did not recognize the custom routing configuration and it took me a while to figure out why it worked in a different scenario.

The gist is, you have to still define a file provider and point it to the very same configuration file. Let's say your Traefik configuration file is stored in a file named config.toml and you mounted the file in the root directory (/) of the Traefik container, then you need to add a file provider definition that looks like this:

[providers]
[providers.file]
directory = "/"
filename = "config.toml"

This way, Traefik will configure all routing information found in the global configuration file and ignore all other configuration parameters.

What I like about this approach is that the whole Traefik configuration is part of one file. For me that is easier when I need to debug things as I only need to have one file open.