我想使用Traefik的多个docker-compose项目作为反向代理 . 按照文档后我创建了两个docker-compose文件;一个用于Traefik,另一个用于具有2个“whoami”容器的示例项目 .
这适用于后端,但似乎Traefik为每个运行容器创建了一个前端 . 因此,除了2个whoami容器的1个前端之外,我还定义了两个前端:“frontend-Host-whoami-localhost-0”和“frontend-Host-whoami-localhost-1” .
如果我扩展whoami服务(通过在docker-compose.yaml文件中复制它们的定义,或者使用 docker-compose scale whoami=10
),Traefik将创建更多的前端 .
我只想要一个“Host:whoami.localhost”规则的前端,该规则指向一个后端,其中连接了多个正在运行的容器 . 我怎样才能做到这一点?
traefik.toml:
defaultEntryPoints = ["http"]
[web]
address = ":8080"
[entryPoints]
[entryPoints.http]
address = ":80"
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "localhost"
docker-compose.yaml(对于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 /泊坞窗,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
1 回答
我想你想要那个:
要做到这一点,你必须使用另一个matcher(例如
PathPrefix
):如果您只想缩放,则只需要在composefile中使用一个服务: