Traefik v2 [how to route to specific port]

Gabriel Bastos picture Gabriel Bastos · Apr 12, 2019 · Viewed 8.8k times · Source

I'm trying to start the change of backends to be compatible with traefik v2.0.

I'm having headache to accomplish a simple task. The old configuration was:

  labels:
    - traefik.port=8500
    - traefik.docker.network=proxy
    - traefik.frontend.rule=Host:consul.{DOMAIN}

I assumed, the network is not necessary anymore, it would change the new traefik for:

    - traefik.http.routers.consul-server-bootstrap.rule=Host('consul.scoob.thrust.com.br')

But how I set, that this should forward to my backend at port 8500? and not 80 where the entrypoint was reached at Traefik?

EDIT

My goal would try to accomplish something like this: https://docs.traefik.io/user-guide/cluster-docker-consul/#migrate-configuration-to-consul

Is it still possible? I saw, there was no --consul or storeconfig command in v2.0

Thanks in regards,

Answer

hdorio picture hdorio · Aug 27, 2019

You need traefik.http.services.{SERVICE}.loadbalancer.server.port

  labels:
    - "traefik.http.services.{SERVICE}.loadbalancer.server.port=8500"
    - "traefik.docker.network=proxy"
    - "traefik.http.routers.{SERVICE}.rule=Host(`{DOMAIN}`)"
  • Replace {SERVICE} with the name of your service.
  • Replace {DOMAIN} with your domain name.

If you want to remove the proxy network you'll need to look at https://docs.traefik.io/v2.0/providers/docker/#usebindportip