Reverse proxy for services outside of the traefik docker-compose.yml


I'm wondering if it's possible to configure traefik in a single docker-compose.yml so it proxies traffict to containers that are already running and are defined in other docker-compose.yml that I would prefer not have to edit.

As an example and to simplify let's say this is the app.docker-compose.yml of the service that is already running (on port 3030) and that I don't want to touch (the real reason being that this is a much bigger project which I don't maintain and with a much more complex docker-compose file than this one)

version: "3.3"

    image: "traefik/whoami"
    container_name: whoami
      - 3030:80

Then I'm trying this on my traefik.docker-compose.yml file:

version: "3.7"
    image: traefik:2.11
      - /var/run/docker.sock:/var/run/docker.sock
      - "80:80"
      - "--api=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entryPoints.web.address=:80"
      - "traefik.enable=true"

      - "traefik.http.routers.whoami.rule=Host(`whoami.local`)"
      - "traefik.http.routers.whoami.service=whoami"
      - ""

whoami.local has been added into my /etc/hosts file.
If I do this:

curl whoami.local

I get from traefik: Bad Gateway.

I also tried actually editing both compose files so they use the same network but I still get the same Bad Gateway error.

So, is it even possible to avoid touching the app.docker-compose.yml file and having traefik.docker-compose.yml routing requests "to it" ?

Thank you

The labels need to go on the target service/container, not on Traefik itself (except for dashboard). Traefik is using the IP from the container the labels is on to forward the requests.

See simple Traefik example.

Alternatively you can create an additional dynamic config file with router and service using loadBalancer.server.url (doc), loading file in static config with providers.file.

Sadly, you can’t configure remote addresses via labels, you can upvote the issue for this feature.