Search code examples
cloudflaretraefik

Traefik : Auto-add subdomains to cloudflare DNS


I use traefik as a reverse proxy for my self hosted services, and it works like a charm. Each time I add a new service, traefik detects it and routes queries accordingly. Each service is routed to a subdomain of my main domain.

The only manual step I still have to do is to add a new record in the DNS for my new subdomain. And I would like to automate it.

I know Cloudflare has an API for managing DNS records, and I can work it out from there. But I don't know if I can hook a script that would be triggered when traefik detects a new subdomain for example...

Any pointers on where I could investigate on the traefik side to detect the event that a new subdomain was added ?


Solution

  • In the end I found a solution that answers my needs :

    https://github.com/tiredofit/docker-traefik-cloudflare-companion

    Internally it listens to the docker events and then re-checks all the running containers to detect if some tags have changed.

    So the hook is not within traefik but rather directly within Docker.