6

I want to use multiple docker-compose projects with Traefik as reverse proxy. After following the documentation I've created two docker-compose files; one for Traefik and one for an example project which has 2 "whoami" containers.

This works great for the backends, but it seems that Traefik creates one frontend per running container. So instead of 1 frontend for the 2 whoami containers, I got two frontends defined: "frontend-Host-whoami-localhost-0" and "frontend-Host-whoami-localhost-1".

Traefik will create more frontends if I scale up the whoami service (by either duplicating their definition in the docker-compose.yaml file, or with docker-compose scale whoami=10).

I just want one frontend for the "Host:whoami.localhost" rule, which points to one backend with multiple running containers attached to it. How can I do this?

traefik.toml:

defaultEntryPoints = ["http"]

[web]
address = ":8080"

[entryPoints]
    [entryPoints.http]
    address = ":80"

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "localhost"

docker-compose.yaml (for traefik):

version: "2"
services:
  traefik:
    container_name: traefik
    image: traefik
    networks:
      - webgateway
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.toml:/traefik.toml
    labels:
      traefik.backend: web
      traefik.frontend.rule: Host:monitor.localhost

networks:
  webgateway:
    driver: bridge

whoami/docker-compose.yaml:

version: "2"
services:
  whoami:
    image: emilevauge/whoami
    networks:
      - webgateway
    labels:
      traefik.backend: whoami
      traefik.frontend.rule: Host:whoami.localhost

  whoami_2:
    image: emilevauge/whoami
    networks:
      - webgateway
    labels:
      traefik.backend: whoami
      traefik.frontend.rule: Host:whoami.localhost

networks:
  webgateway:
    external:
      name: traefikdocker_webgateway
Wessel van der Linden
  • 2,592
  • 2
  • 21
  • 42
  • 1
    Did you find a solution? – larsw Jun 14 '18 at 13:20
  • 1
    @larsw, what is the issue here? Though you see multiple frontends it is still load balanced when you use the host `whoami.localhost`, you can verify that using `curl -H whoami.localhost http://localhost` – Tarun Lalwani Jun 14 '18 at 16:46
  • 1
    Yes, I see multiple frontends, but as far as I can tell, it really shouldn't be needed. Looking at some recent bug reports and PR / merges, AFAIK it should have been fixed - but it doesn't work as expected for me. – larsw Jun 15 '18 at 06:30
  • 1
    @larsw no I didn't unfortunately. If I use docker swarm with traefik, then it'll create one frontend with multiple backends. But "just" using docker compose (v2) still creates multiple frontends. – Wessel van der Linden Jun 15 '18 at 06:42
  • 1
    @larsw after updating to a newer version (1.6.4) the problem was solved. I now see one frontend with multiple backends (without using docker swarm) – Wessel van der Linden Jun 17 '18 at 12:15

1 Answers1

1

I suppose you want that:

http://example.com/
|-> app1 who serve http://example.com/foo
|-> app2 who serve http://example.com/bar

To do that you must use another matcher (like PathPrefix by example):

traefik.frontend.rule: Host:http://example.com/; PathPrefix:/foo
|-> app1 who serve http://example.com/foo

traefik.frontend.rule: Host:http://example.com/; PathPrefix:/bar
|-> app2 who serve http://example.com/bar

If you just want to scale, you only need one service in your composefile:

traefik.frontend.rule: Host:http://example.com/
|-> 10 x app (docker-compose scale app=10)
ldez
  • 3,030
  • 19
  • 22