我有两个基本的烧瓶应用程序,我为此创建了容器。我正在尝试使用traefik来访问“ localhost”(即将被实际域替换)时路由到一个容器,并在访问“ localhost / app2”时路由到另一个容器。当我进行docker-compose并访问trafik仪表板时,我可以看到URL已创建并且可以成功访问它们。我可以访问“ localhost”,它可以正确路由到我的第一个烧瓶应用程序,但是“ localhost / app2”使我出现404 / Not found错误,可能是因为它仍在访问该第一个应用程序。如何正确路由第二个应用程序?这是我的docker-compose文件:
version: '3'
services:
app1:
build: .
command: /usr/bin/python3 fapp1.py
networks:
- test_network
- internal
ports:
- "8000:8000"
labels:
- "traefik.frontend.rule=Host:localhost"
app2:
build: .
command: /usr/bin/python3 fapp2.py
networks:
- test_network
- internal
ports:
- "8001:8001"
labels:
- "traefik.frontend.rule=Host:localhost/app2"
reverse-proxy:
image: traefik # The official Traefik docker image
command: --api --docker # Enables the web UI and tells Traefik to listen to docker
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker eventsdoc
networks:
- test_network
- internal
networks:
test_network:
external: true
internal:
external: false
以及为各个应用创建的网址:
app1:http://172.23.0.3:8000/ app2:http://172.23.0.4:8001/
谢谢!