tiredofit / docker-traefik-cloudflare-companion

Automatically Create CNAME records for containers served by Traefik

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for creating multiple CNAMES per container

tehniemer opened this issue · comments

With Traefik 2 you can create multiple subdomains for a single container, like so

      - "traefik.http.routers.foobar-rtr.rule=Host(`foo.$DOMAIN_NAME`,`bar.$DOMAIN_NAME`)" 

or like so

      - "traefik.http.routers.foobar-rtr.rule=Host(`foo.$DOMAIN_NAME`)"
      - "traefik.http.routers.foobar-rtr.rule=Host(`bar.$DOMAIN_NAME`)"

It seems that only one subdomain per container is seen by this tool and only a single CNAME is created. It would be nice if this tool would catch and create all of the CNAMES defined in a container's compose file with either method of formatting in these examples.

Correct, at this time it's only catching your first example.

Is this something that could happen in a future release?

commented

It's not catching anything. There is no way for now to have more than one created this way, so I can't use it at all for now.

At this time, since it is working with Option #1 it's a fairly low priority for me. It's not that I don't want to help, it's that my Python skills are terrible. I maintain 60 other projects right now and there are half a dozen that need some important updates and love that I'm focusing my efforts on. I'm definitely willing to take PR's from contributors providing that they don't introduce massive breakage.

@max2770 Are you using swarm?

commented

@max2770 Are you using swarm?

Nope, plain old Traefik 2 on Docker on top of Ubuntu Server 20.04. Option 1 doesn't pull anything, option 2 pulls the last one. Funny enough, I learned about it from htpcBeginner/docker-traefik 's sample Docker-Compose file line 1962 so I assume it works for him... Weird.

@max2770 This deserves a seperate issue TBH, I'm willing to investigate it. I have 600 give or take web services that are being used by this container and it's working rather well for us either on Single host and multihost (Option #1).

Open one and let's try to figure out what is happening here..

commented

@max2770 This deserves a seperate issue TBH, I'm willing to investigate it. I have 600 give or take web services that are being used by this container and it's working rather well for us either on Single host and multihost (Option #1).

Open one and let's try to figure out what is happening here..

I'll be honest I've worked on my config all day, I'll go to bed and try again tomorrow. If I have the same issue I'll open a new one.

No problem.

I think I found the problem. I have been successful with single host, but not with multihost using either option, I've scoured the logs and found this

Found Container: 9b93137b2bfd8416b7df1dbf645a847b40891cef265099f944c8658a5b9e1ad2 with Hostname example.com`,`www.example.com`,`foobar.example.com,
container rule value:  HostHeader(`example.com`,`www.example.com`,`foobar.example.com`),
extracted_domains from rule:  [u'example.com`,`www.example.com`,`foobar.example.com'],
** example.com`,`www.example.com`,`foobar.example.com - 1004 DNS Validation Error

This is the formatting used in the compose file

      - "traefik.http.routers.foobar-rtr.rule=Host(`$DOMAIN_NAME`,`www.$DOMAIN_NAME`,`foobar.$DOMAIN_NAME`)"

If I could get multihost working with option #1 I'd be happy.

Sorry, I've gapped entirely. What we have listed here for Option 1 would be for Traefik 1.
Here's what I use for Traefik 2.

traefik.http.routers.example.rule=Host(`example.domain.tld`) || Host(`example2.domain.tld`) || Host(`example3.domain.tld`)`

I made that change and it seems that only the final entry is being created, similar to option #2 above.

container rule value:  Host(`example.com`) || Host(`www.example.com`) || Host(`foobar.example.com`),
extracted_domains from rule:  [u'foobar.example.com'],
Found Container: 5c16165c73c126462606a4612639680d79ea358e511a7a36e7a0a36e05e1b452 with Hostname foobar.example.com

I am seeing the same now. Something has changed. To investigate today.

I've identified the issue - Terribly sorry. This broke when introducing support for Traefik 2.2.2 a few weeks back. A new tag tiredofit/traefik-cloudflare-companion:latest and tiredofit/traefik-cloudflare-companion:4.2.1 is now available on Docker Hub

commented

Awesome, thanks! So the right way of doing it is

- "traefik.http.routers.foobar-rtr.rule=Host(`foo.$DOMAIN_NAME`,`bar.$DOMAIN_NAME`)"

or

- "traefik.http.routers.example.rule=Host(`example.domain.tld`) || Host(`example2.domain.tld`) || Host(`example3.domain.tld`)"

to have it work?

Thanks!

Here's the rule I'm using for testing. Multilined labels and hosts (meaning that docker-compose you pointed me to from htpcbeginner) are not working.

- traefik.http.routers.example.rule=Host(`example1.domain.tld`) || Host(`example2.domain.tld`)

Log output:

container rule value:  Host(`example1.domain.tld`) || Host(`example2.domain.tld`)
extracted_domains from rule:  [u'example1.domain.tld', u'example2.domain.tld']
Found Container: 31440649a67bc993bd4d1dd20ec4dde201b7298b68282246ddbb381b4cd3b76d with Multi-Hostname example1.domain.tld
Found Container: 31440649a67bc993bd4d1dd20ec4dde201b7298b68282246ddbb381b4cd3b76d with Multi-Hostname example2.domain.tld

README now updated with examples for both version 1 and version 2 for Multi Hostnames

Working now, thanks for the quick work!

Sorry to re-open. Minor change,

- traefik.http.routers.example.rule=Host(example1.domain.tld) || Host(example2.domain.tld)`

With the latest version of traefik, shouldn't it be HostHeader instead of Host?

There's a wildcard that should allow Host, HostSNI, HostHeader etc...