Using .env (hidden file) environment variables in seperate config files

Following this How to use environment variables in the dynamic configuration (using file provider)? I adapted and use

      rule: "Host(`idrac1.{{env "DOMAINNAME"}}`)"

DOMAINNAME comes from a hidden file named .env and is used in the docker-compose.yml file and called using $DOMAINNAME. Why is it that I have to put - DOMAINNAME under the environment: for traefik in dockercompose? originally i thought it would work like this

      rule: "Host(`idrac1.$DOMAINNAME`)"

I'm assuming the docker compose process has access to the .env file entries, but to pass it to traefik directly the environment: thingy needs to called explicitly?

Hello @rombo,

You have to do so in order for Traefik to be able to get this configuration from the environment inside the container.

Indeed, docker-compose have access to the .env file and can read it. If you want to 'forward' the environment variable, you can do:

services:
  traefik:
    ...
    environment:
      DOMAINNAME: $DOMAINNAME

Hope it helps :slight_smile: