问题描述
我一直在尝试使用基本官方指南设置traefik v2.2。我有一个已容器化的Spring Boot服务,并且工作正常。
这是我的spring boot服务的docker组成:
version: "3"
services:
spring-boot-traefik-app:
image: spring-boot-traefik-example:latest
labels:
- "traefik.http.routers.spring-boot-traefik-app.rule=Host(`springboot.traefik.app`)"
这是我的Traefik docker compose:
version: "3"
services:
reverse-proxy:
# The official v2 Traefik docker image
image: traefik:v2.2
# Enables the web UI and tells Traefik to listen to docker
command:
- "--api.insecure=true"
- "--providers.docker=true"
ports:
# The HTTP port
- "80:80"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
现在,我正在尝试通过以下方式进行卷曲请求:
curl -H Host:springboot.traefik.app http://127.0.0.1
由于我只是在上下文路径“ /”上返回服务信息,因此它应该已经向我返回了一些信息。服务独立运行良好。但是,当我尝试在代理后面运行时,会给我网关超时错误。我不确定traefik是否运作正常。我想念什么吗?官方指南使用的是whoami映像,这是我正在尝试通过Spring boot创建的映像。另外,traefik仪表板可以正确显示详细信息。
解决方法
也许您应该为traefik配置定义一个入口点。您可能没有traefik.toml文件(我更喜欢个人使用)。无论如何,您应该为traefik容器添加命令--entryPoints.web.address=:80
,并在springboot容器中添加标签traefik.http.routers.spring-boot-traefik-app.entrypoints=web
。我希望它能起作用!