# Environment variable access in the docker-compose file?

**URL:** <https://community.traefik.io/t/environment-variable-access-in-the-docker-compose-file/18802>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [June 2, 2023, 6:25am UTC](https://community.traefik.io/t/environment-variable-access-in-the-docker-compose-file/18802 "2023-06-02T06:25:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joerg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/joerg/32/7188_2.png) [@Joerg](https://community.traefik.io/u/Joerg)\
**Post date:** [June 2, 2023, 6:25am UTC](https://community.traefik.io/t/environment-variable-access-in-the-docker-compose-file/18802/1 "2023-06-02T06:25:16Z")

</div>

Hello,

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**

```auto
version: '3.9'

services:
  traefik:
    image: traefik:v3.0
    container_name: traefik
    env_file:
      - ./.traefik.env
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      # 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
      - TRAEFIK_ENTRYPOINTS_WEBSECURE_ADDRESS=:443 # sets the port for HTTPS
    ports:
      - "80:80"
      - "443:443"
    labels:
      # 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**

```auto
TRAEFIK_URL=traefik.localhost
LOG_LEVEL=DEBUG

```

---

<div class="post-metadata">

**Author:** ![Joerg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/joerg/32/7188_2.png) [@Joerg](https://community.traefik.io/u/Joerg)\
**Post date:** [June 5, 2023, 6:30am UTC](https://community.traefik.io/t/environment-variable-access-in-the-docker-compose-file/18802/2 "2023-06-05T06:30:21Z")

</div>

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 (-;

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [June 8, 2023, 6:30am UTC](https://community.traefik.io/t/environment-variable-access-in-the-docker-compose-file/18802/3 "2023-06-08T06:30:38Z")

</div>

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