Traefik-v2-examples icon indicating copy to clipboard operation
Traefik-v2-examples copied to clipboard

Could it be possible to use the "environment:" parameter to pass variables

Open ZJohnAsZ opened this issue 1 year ago • 0 comments

Not so much to report an issue but a way to pass .env and secrets files variables to the traefik.yaml

I am not yet well versed with docker compose, but came across your Github helping README and many others while making my yaml files Could it be possible to use the "environment:" parameter to pass them from the main docker-compose file to the traefik file by using the "environment:" parameter.

EG.: traefik-docker-compose.yaml

################################################################

SECRETS

################################################################ secrets: htpasswd: file: $SECRETSDIR/.htpasswd cf_email: file: $SECRETSDIR/.cf_email cf_api_key: file: $SECRETSDIR/.cf_api_key

################################################################

SERVICES: TRAEFIK v2 - Reverse Proxy

################################################################ services: traefik: container_name: traefik image: traefik:2.10 restart: always secrets: # secrets files to load for this container - cf_email - cf_api_key - htpasswd environment: # passing secrets and .env environments so they can be used in traefik.yaml - TZ=$TZ - CLOUDFLARE_IPS=$CLOUDFLARE_IPS - CF_API_EMAIL_FILE=/run/secrets/cf_email - CF_API_KEY_FILE=/run/secrets/cf_api_key - HTPASSWD_FILE=/run/secrets/htpasswd - DOMAINNAME_MAIN=$DOMAINNAME_MAIN

So, you are kind of passing the .env variable from the main linux environment to the container environment to use it in traefik.yaml? Anyway, I thought it could help some others whom may find your github. I spend so much time trying to understand what I am doing making those traefik reverse proxy .yaml files. I hope it works when I finally up them. XD

ZJohnAsZ avatar Jan 17 '24 18:01 ZJohnAsZ