我的配置是一个简单的Docker Swarm(在Windows的Docker上),带有Treafik容器和一个非常简单的Spring Boot'echo'容器。
我想将对“ localhost / traefik”的浏览器请求转发至Traefik仪表板,并将“ localhost / echo / something”转发至简单的Sprint Boot回显应用程序。
预期可工作:
localhost/treafik => gives a "Gateway timeout" localhost/echo/something => gives a "Gateway timeout"
预计不起作用,但绕过Traefik(不正确):
localhost:8080 => shows the Traefik dashboard localhost:8082/echo/something => { "status":"something" }
如何改善docker-compose.yml文件以获得预期结果?这与“联网”有关吗?创建任何网络(甚至是覆盖网络)时,都会出现错误消息。
version: '3.7'
services:
traefik:
image: traefik:latest
command: --api --docker
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- //k/data/slackbot/traefik.toml:/traefik.toml
ports:
- "80:80"
- "8080:8080"
labels:
- "traefik.enable=true"
- "traefik.frontend.rule=Host:localhost;PathPrefixStrip:/traefik"
- "traefik.port=8080"
- "traefik.protocol=http"
- "traefik.backend=traefik"
slackbotsimple:
image: solvedshared/slackbotsimple:latest
ports:
- 8082:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
- "traefik.enable=true"
- "traefik.frontend.rule=Host:localhost;PathPrefix:/echo"
- "traefik.port=8082"
- "traefik.protocol=http"
- "traefik.backend=slackbotsimple
答案 0 :(得分:2)
第一个问题是网络问题。解决了,感谢聪明的吉姆。
另一个问题是我使用了错误的端口号。从前端“ / echo”路由到后端,不使用“端口”部分。我可以直接路由到slackbot应用程序的公开端口!
看看端口配置:只有80个可用。
version: '3.7'
services:
traefik:
image: traefik:latest
command: --api --docker
restart: always
networks:
- slackbotnet
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- //k/data/slackbot/traefik.toml:/traefik.toml
ports:
- "80:80"
labels:
- "traefik.enable=true"
- "traefik.docker.network=slackbotnet"
- "traefik.frontend.rule=Host:localhost;PathPrefixStrip:/traefik"
- "traefik.port=8080"
- "traefik.protocol=http"
- "traefik.backend=traefik"
slackbotsimple:
image: solvedshared/slackbotsimple:latest
networks:
- slackbotnet
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
- "traefik.enable=true"
- "traefik.docker.network=slackbotnet"
- "traefik.frontend.rule=Host:localhost;PathPrefix:/echo"
- "traefik.port=8080"
- "traefik.protocol=http"
- "traefik.backend=slackbotsimple"
networks:
slackbotnet:
name: slackbotnet