traefik

Traefik notation in docker-compose to enable access with and without default domain


I am trying to use traefik to route to a docker container (gitea in my case, but that should not be relevant) in my local network. My network runs DHCP with a default domain (e.g. "my.lan"). The docker host (running both gitea and traefik) has a statically assigned DHCP-address with the default domain set.

From my desktop, both the long form with full domain my-git.my.lan and the short form my-git correctly resolve to the IP address of the docker container (essentially an entry in my DNS).

What is the proper way to specify the host name for the traefik route (in docker-compose), so that both, the long form as well as the short form work correctly?

When I use the following label (with full domain):

- "traefik.http.routers.gitea.rule=Host(`my-git.my.lan`)"

then I can get to the container using the full path http://my-git.my.lan in the browser, but not with the shorthand http://my-git, which gives me "404 page not found".

However, when I use the following label (no domain):

- "traefik.http.routers.gitea.rule=Host(`my-git`)"

then I can get to the container using http://my-git, but not via the long path, which gives me a "404 page not found".


Solution

  • Use a logical operator:

    .rule=Host(`my-git`) || Host(`my-git.my.lan`)