Multiple Hosts rule syntax

Hi,

I am trying to migrate from v1.7 where the new Host rules syntax is a bonebreaker for me.

I have multiple Domains which need to be attached to multiple Swarm Services

So I used to have env files containing variables like:

PRIMARY_DOMAINS=somedomain1.com,anotherdomain2.com,yougetthepoint.com
SECONDARY_DOMAINS=foobar3.com,bazbaz4.com

then I defined in old v1 syntax for docker-compose.yml v3:

    deploy:
      labels:
        - "traefik.port=80"
        - "traefik.myservice.frontend.rule=Host:${PRIMARY_DOMAINS},${SECONDARY_DOMAINS};PathPrefixStripRegex:/{lang:(([a-z]{2}|[a-z]{2}-[a-z]{2}))}/api"

this way, I could reuse the same domains on all Services I define and the number of domains remain variable, which is very important.

With the new v2 syntax, I can't figure out how to glue the domains together since they should be declared one by one with backtick limiters and explicit Host definitions like this

        - "traefik.http.routers.myservice.rule=( Host(`somedomain1.com`) || Host(`anotherdomain2.com`) || Host(`yougetthepoint.com`) || Host(`foobar3.com`) || Host(`bazbaz4.com`) ) && PathPrefix(`/{lang:(([a-z]{2}|[a-z]{2}-[a-z]{2}))}/api`)"

Is there any way to inject them like in a Range/End-like-Templating-Loop (as we know from consul-template, for example) or how is this supposed to be done now? Remember, the number of domains must be variable

Thanks a lot!

2 Likes