Traefik - Generic labels to prevent compose.yml growth and copy/paste madness ? reddit / selfhosted ---------------------------------------------------------------------- niawagj · 2023-12-20 16:29 Hi, I've spent some times searching for this and found some leads (with default rule) but I'm still not sure if what I'm trying to achieve is possible, hence my question! I'd like to write generic labels for traefik in service definition (docker compose, standalone) to replace this: ``` labels:       - "traefik.enable=true"     - "traefik.http.routers.kumanuc-rtr.entrypoints=https"       - "traefik.http.routers.kumanuc- rtr.rule=Host(kumanuc.mydomain.com)"       - "traefik.http.routers.kumanuc-rtr.tls=true"       - "traefik.http.routers.kumanuc-rtr.service=kumanuc-svc"     - "traefik.http.routers.kumanuc-rtr.middlewares=localip" ``` By something like this, the would be a variable read when running' docker compose up' : ``` labels:       - "traefik.enable=true"     - "traefik.http.routers.-rtr.entrypoints=https"       - "traefik.http.routers.-rtr.rule=Host(.mydomain.com)"       - "traefik.http.routers.-rtr.tls=true"       - "traefik.http.routers.-rtr.service=-svc"       - "traefik.http.routers.-rtr.middlewares=localip" ``` If I can do this, then I can move all this in an extension (https://docs.docker.com/compose/compose-file/11-extension/) at the top of my compose file and just call them when needed. It would look like that: ``` x-traefik-labels: &traefik-labels labels:       - "traefik.enable=true"       - "traefik.http.routers.-rtr.entrypoints=https"       - "traefik.http.routers.-rtr.rule=Host(.mydomain.com)"       - "traefik.http.routers.-rtr.tls=true"       - "traefik.http.routers.-rtr.service=-svc"       - "traefik.http.routers.-rtr.middlewares=localip" services: kuma: image: louislam/uptime-kuma:latest container_name: kuma volumes: - ./kuma:/app/data <<: *traefik-labels jellyfin: container_name: jellyfin image: jellyfin/jellyfin:latest volumes: - ./jellyfin/config:/config - ./jellyfin/cache:/cache - /mnt/multimedia:/media devices: - /dev/dri/renderD128:/dev/dri/renderD128 - /dev/dri/card0:/dev/dri/card0 <<: *traefik-labels ... ``` Does anyone know if this is possible ? PS: I tried to post it in /traefik but my karma is too low so I came here because I think lots of selfhosted enthousiasts are using docker and traefik ---------------------------------------------------------------------- sk1nT7 · 2023-12-20 17:51 Unsure whether it helps but my traefik static config holds many defaults, which then must not be defined as label later on. You can enable or set the default route for the docker provider and therefore neglect specifying the hostname. You can also define the default middlewares enabled for all proxy hosts. SSL/TLS auto redirect is in my case always on, so no need to add any additional rewrite rules. You can also define the default network for traefik. Here the example config: https://github.com/Haxxnet/Compose- Examples/tree/main/examples%2Ftraefik For a new service, I only have a subset of labels to set. Basically enable traefik to expose the service, maybe overwrite the subdomain to listen on and then some specifics like the service listening port or whether I want to increase the upload max size or some non-default middlewares. The template can be found here: https://github.com/Haxxnet/Compose- Examples/blob/main/0_skeleton%2Fdocker-compose.yml#L27-L39 That's just my way of doing it. ---------------------------------------------------------------------- niawagj · 2023-12-21 08:07 >Thanks for your help, I'll look into it and adapt it to my setup to see how much it help reducing the copy/paste frenzy!