Routers rules and 2 competing docker containers

Hi,
I would like to add another docker container to an existing traefik environment. The first app handles all http and https requests with the following docker-compose configuration:

labels:
  - "traefik.enable=true"
  - "traefik.http.routers.lime-https.rule=Host(`hostname.com`)"
  - "traefik.http.routers.lime-http.rule=Host(`hostname.com`)"
  - "traefik.http.middlewares.redirect.redirectscheme.scheme=https"
  - "traefik.http.middlewares.redirect.redirectscheme.permanent=true"
  - "traefik.http.routers.lime-http.middlewares=redirect"
  - "traefik.http.routers.lime-https.entrypoints=websecure"
  - "traefik.http.routers.lime-http.entrypoints=web"
  - "traefik.http.routers.lime-https.tls.certresolver=myresolver"
networks:
  - web

I would like to add the second app, which would be targeted by hostname.com/app/. However, the following configuration does not work. Still the first app responses with 404 error:

labels:
  - "traefik.enable=true"
  - "traefik.http.routers.xnat.rule=PathPrefix(`/xnat/`)"
  - "traefik.http.routers.xnat.entrypoints=websecure"
  - "traefik.http.routers.xnat.priority=1"
  - "traefik.http.services.xnat-service.loadbalancer.server.port=8080"
  - "traefik.http.routers.xnat.service=xnat-service"
networks:
  - web

Please let me know how to solve the problem.
Bartek

Hello @malywladek,

From the documentation: (https://docs.traefik.io/v2.1/routing/routers/#priority), priority is an ordered number.

Therefore priority 100 will match before priority 1.

By setting your second service to a priority of 1, every other service will be matched first.

Try it with a priority of 100.

Thank You for the quick reply but the change of priority does not help.

I assume this is a typo and should be /xnat/

  • Your routers lime-https and xnat need tls enabled.
  • The priority was an issue.
  • You likely want a (Host(`hostname.com`) && Path(`/xnat/`)) rule.
  • traefik.http.routers.xnat.service is not required, it is implicit from the docker service/container

Thank You for the responses. Indeed I have copied configuration from the first app and modified the names. Also I have added priority and it seems to work. However, I have an additional question regarding my application. What if hostname.com/app redirects to eg. hostname.com/login for authorisation. Can Traefik handle such requests?
B.

The app is sending the redirect? Update an existing rule to match it or add a new route/service.

Same app handles uri
.....rule=(Host(`hostname.com`) && (Path(`/xnat/`) || Path(`/login`)) )

If another service does /login then the same pattern of adding traefik labels for a new router.