Environment variable access in the docker-compose file?


I am quite new to Traefik, and I am stuck at the moment with a problem I hope somebody here could help me with.

In my docker-compose file, I want to hide some of my variables with help of environment variables. In the same folder as my docker-compose file, I have a file called "traefik.env" with two key-value pairs.
"TRAEFIK_URL=traefik.localhost" and "LOG_LEVEL=DEBUG". In my compose file, I reference my env. file with the "env_file:" docker tag. The issue I'm having is that the variables are not read by docker or traefik. This is the warning I get: "WARN[0000] The "LOG_LEVEL" variable is not set. Defaulting to a blank string. "

What do I do wrong in my setup? Any other suggestions regarding my setup is appreciated. Thanks in advance for your help.

my docker-compose file

version: '3.9'

    image: traefik:v3.0
    container_name: traefik
      - ./.traefik.env
      - /var/run/docker.sock:/var/run/docker.sock
      # Traefik API
      - TRAEFIK_API=true # enables the Traefik API. True by default
      - TRAEFIK_API_INSECURE=true # allow access to the Traefik API over an insecure connection (HTTP).
      - TRAEFIK_API_DASHBOARD=true # enables the Traefik dashboard. True by default.
      # Logging configuration
      - TRAEFIK_LOG_LEVEL=${LOG_LEVEL} # sets the log level (DEBUG, INFO, WARN, ERROR, FATAL, PANIC). DEBUG by default
      - TRAEFIK_ACCESSLOG_FILTERS_STATUSCODES=400-499,500-599 # filters access logs to only include 400 and 500 level errors
      # Provider configuration
      - TRAEFIK_PROVIDERS_DOCKER=true # enables the Docker provider
      - TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT=false # prevents Traefik from creating routes for containers that don't have a traefik.enable=true label
      - TRAEFIK_PROVIDERS_DOCKER_WATCH=true # tells Traefik to listen to Docker events
      # Entrypoints configuration
      - TRAEFIK_ENTRYPOINTS_WEB_ADDRESS=:80 # sets the port for HTTP
      - "80:80"
      - "443:443"
      # Traefik configuration
      - "traefik.enable=true" # enables Traefik for this container
      # Routers configuration
      - "traefik.http.routers.traefik.rule=Host(`${TRAEFIK_URL}`)" # sets the hostname for the Traefik dashboard route
      - "traefik.http.routers.traefik.entrypoints=web" # sets the entrypoint for the Traefik dashboard route
      - "traefik.http.routers.traefik.service=api@internal" # ensures that the Traefik dashboard route is linked to the internal Traefik API service
      - "traefik.http.routers.traefik.middlewares=auth" # applies the auth middleware to the Traefik dashboard route
      # Services configuration
      - "traefik.http.services.traefik.loadbalancer.server.port=8080" # sets the port for the Traefik dashboard service

My env file


Solved my own problem (-:

I had to change the name of the ".traefik.env" file to ".env", and now it seems to work. It also looks like that I don't need to specify where the env file is located. If changing it to the above-mentioned, docker knows where to look for. Smart (-;

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.