我只是试图将现有的非常简单的Traefik设置升级到2.0。
我正在使用Docker作为提供程序。
我正在使用docker-compose运行容器。这是我的docker-compose配置:
version: "3.5"
services:
traefik:
image: traefik:v2.0-alpine
read_only: yes
ports:
- 80:80
- 443:443
volumes:
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
- type: bind
source: ./traefik.toml
target: /traefik.toml
- type: bind
source: ./acme.json
target: /acme.json
networks:
- traefik
example:
image: example.com/example/example
labels:
- "traefik.enable=true"
- "traefik.frontend.rule=Host:example.com"
- "traefik.docker.network=traefik"
networks:
- traefik
这是我的traefik.toml
:
defaultEntryPoints = ["http", "https"]
[Global]
sendAnonymousUsage = true
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[acme]
email = "ssl@example.com"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
onDemand = false
acmeLogging = true
[acme.tlsChallenge]
[docker]
exposedByDefault = false
此设置可在Traefik 1.7上正常运行。
在Traefik 2.0中,我观察了两个问题,查看了ACME日志:
Unable to obtain ACME certificate for domains traefik-example-deployment
Unable to obtain ACME certificate for domains example-example-deployment
traefik.frontend.rule=Host:example.com
标签。我怀疑这可能是由于Traefik 2.0中的配置格式更改所致。但是,尽管我浏览了2.0文档,但仍无法看到正确的配置。
答案 0 :(得分:0)
路由器¶
要更新自动附加到容器的路由器的配置,请添加标签,标签以traefik.routers.{name-of-your-choice}.
开头,后跟要更改的选项。例如,要更改规则,可以添加标签traefik.http.routers.my-container.rule=Host(my-domain).
每个路由器参数都可以用这种方式更新。 如文档中所述-https://docs.traefik.io/v2.0/providers/docker/
将labels:
更改为
services:
my-container:
# ...
labels:
- traefik.http.routers.my-container.rule=Host(`my-domain`)
要告诉Traefik不要公开容器-添加-traefik.enable=false
为traefik
默认情况下通过Traefik公开容器。如果设置为false,则没有traefik.enable=true
标签的容器将从生成的路由配置中忽略。
exposedByDefault (Optional, Default=true)¶