Traefik loadbalancer server port

i have a few services in my docker-compose file using traefik labels.

now i would like to clean this file and start using traefik yaml files.

the problem is that i could not find the equivalent to traefik.http.services.dnsmasq-traefik.loadbalancer.server.port=5380

and there arent any examples in the docs


the labels (this works perfectly)

- "traefik.http.routers.dnsmasq.rule=Host(`dnsmasq.docker.localdomain`)"
- "traefik.http.routers.dnsmasq.service=dnsmasq-traefik@docker"
- "traefik.http.services.dnsmasq-traefik.loadbalancer.server.port=5380"

the yaml (not working, gives me a Gateway Timeout)

http:
    routers:
        dnsmasq-preauth:
            entryPoints: [http]
            middlewares: [redirect-to-http]
            service: dnsmasq-preauth
            rule: Host(`dnsmasq.docker.localdomain`)

    services:
        dnsmasq-preauth:
            loadBalancer:
                servers:
                    - url: "http://dnsmasq.docker.localdomain:5380"
1 Like

Hello,

In container the IPs are dynamic, so you have the fields port and scheme

But with the file provider, you have to explicitly set the complete URL with the field url.

If you are using Docker, I recommend to don't use the file provider.

i really didn't expect that...

i was under the impression that all fields were mapped between providers, meaning they would all be available regardless of type.

thank you for the quick answer.

Just be to sure:

- "traefik.http.routers.dnsmasq.rule=Host(`dnsmasq.docker.localdomain`)"
- "traefik.http.routers.dnsmasq.service=dnsmasq-traefik@docker"
- "traefik.http.services.dnsmasq-traefik.loadbalancer.server.port=5380"

it don't expose dnsmasq.docker.localdomain:5380 but route dnsmasq.docker.localdomain to the port 5390 of the application.

The port used by your router (traefik.http.routers.dnsmasq) is the port of the entrypoint define on this router.

By example, if you have an entry point (test) on port 9999:

- "traefik.http.routers.dnsmasq.rule=Host(`dnsmasq.docker.localdomain`)"
- "traefik.http.routers.dnsmasq.entrypoints=test"
- "traefik.http.routers.dnsmasq.service=dnsmasq-traefik@docker"
- "traefik.http.services.dnsmasq-traefik.loadbalancer.server.port=5380"

you can access to your application on dnsmasq.docker.localdomain:9999