Setting fallback server for all non-found backends

Hi,

I am trying to setup a fallback of services with a change of hostname.
So my service is serving locally under this name: xxx.dev.company.com and would like to setup traefik to fallback to xxx.company.com if the backend is not availble.

I cant find any way to do that.
Any idea ?

Hello,

could you provide more information about your configuration? (traefik.toml, docker-compose file, etc.)

Hello,

so one of my docker-compose file would like that:

labels:
      - "traefik.port=12001"
      - "traefik.enable=true"
      - "traefik.domain=dev.test.com"
      - "traefik.backend=backend1"
      - "traefik.backend.healthcheck.path=/"
      - "traefik.frontend.rule=Host: backend1.dev.test.com"

This backend needs to speak to another backend, and this another can be on your machine (then it would like work perfectly without a chagne), or if it is not started on your machine it should fallback to
backend2.test.com (so no .dev in the domain name).

What I need is a modifier on the host part

regards

This label is used when you don't define a traefik.frontend.rule, then in your case you don't need this label.

Sets the default base domain for the frontend rules. For more information, check the Container Labels section's of the user guide "Let's Encrypt & Docker"

https://docs.traefik.io/v1.7configuration/backends/docker/#on-containers

You asking for a weird behavior: a kind of URL fallback.

I see 2 solutions:

  • create a dummy frontends with on redirection on it. (+ a lower priority than the .dev frontend)
  • add a 2nd domain to the host rule of the frontend without .dev (+ a lower priority than the .dev frontend)

Something like that:

services:
  service-test-dev:
    # ...
    labels:
    - "traefik.port=12001"
    - "traefik.enable=true"
    - "traefik.backend=backend1"
    - "traefik.backend.healthcheck.path=/"
    - "traefik.frontend.rule=Host:backend1.dev.test.com"
    - "traefik.frontend.priority=40"

  service-test:
    # ...
    labels:
    - "traefik.port=12001"
    - "traefik.enable=true"
    - "traefik.backend=backend1"
    - "traefik.backend.healthcheck.path=/"
    - "traefik.frontend.rule=Host:backend1.test.com,backend1.dev.test.com"
    - "traefik.frontend.priority=10"

Documentation:

Hi Idez,
Thanks for your answer.
(this is not a weird behavior, this is called Ambassador pattern when you have multiple services, but this is not the topic ...)

I cant do what you said, the "fallback" services are not in docker-compose, they are just deployed