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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With