Environment variables in traefik.yaml and dynamic.yaml not working

Hi everyone,

I’m having trouble using environment variables in Traefik v3.3 when defining them inside traefik.yaml and dynamic.yaml. I have ensured that the environment variables are correctly set, but they don’t seem to work when referenced in my configuration.

I’ve tried multiple syntax variations for setting a rule like this:
rule: "Host(``)"

Here are some of the syntaxes I’ve attempted:

• {{ env "SERVER_HOST" }}

• %%SERVER_HOST%%

• ${SERVER_HOST}

• {{ env "SERVER_HOST" }}

• (and a few other variations I can’t recall)

Unfortunately, none of these have worked.

Could someone provide guidance on how to correctly use environment variables in Traefik 3.3 configuration files? Any help would be greatly appreciated!

Thanks in advance.

Check the doc:

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

{{ env "MY_ENV_VAR" }}

Alternatively you can place your static and dynamic config in docker compose (instead of Traefik config file), there templating usually works.