我正在尝试运行docker traefik v2.0以使用自签名证书
这是我的traefik.toml文件
logLevel = "DEBUG"
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "/certs/server.crt"
keyFile = "/certs/server.key"
这是我的traefik.yaml docker-compose文件 版本:“ 3.5”
services:
traefik:
image: traefik:v2.0
container_name: traefik
restart: always
networks:
- traefik_network
ports:
- "80:80"
- "443:443"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik.toml:/traefik.toml
- ./certs:/certs/
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
networks:
traefik_network:
name: traefik_network
证书位于certs/server.crt
和certs/server.key
文件夹中
但是当我为traefik运行docker-compose时,出现以下错误
Attaching to traefik
traefik | 2019/10/20 21:08:11 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:08:14 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:08:17 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:08:19 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:08:22 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:08:24 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:08:29 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:08:36 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:08:50 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:09:16 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:10:08 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:11:09 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:11:14 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:11:17 command traefik error: field not found, node: tls
traefik | 2019/10/20 21:11:19 command traefik error: field not found, node: tls
有人知道这是什么问题吗? 谢谢
答案 0 :(得分:0)
根据migration documentation from Traefik v1 to v2,TLS的配置不再在入口点中,而是在路由器的配置中:
您必须定义一个类似于
的路由器(如果仍使用v1的前端/后端,请遵循迁移文档)[http.routers]
[http.routers.Router-1]
rule = "Host(`bar.com`)"
service = "service-id"
[http.routers.Router-1.tls]
options = "myTLSOptions"
# will terminate the TLS request
其中您可以使用myTLSOptions
作为对TLS选项部分的引用,其定义如下:
[tls.options]
[tls.options.myTLSOptions]
minVersion = "VersionTLS13"
cipherSuites = [
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
...
]
...
证书的位置在单独的配置条目中:
[[tls.certificates]]
certFile = "/certs/server.crt"
keyFile = "/certs/server.key"
请注意,您还可以在v2中为配置使用其他格式:您可以使用docker标签做更多的事情,并且如果愿意,还可以从toml更改为yaml。