我正在尝试学习和使用 traefik。 这是我的 docker-compose.yaml:
version: "3"
services:
traefik:
image: "traefik:v2.0"
container_name: "traefik"
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- ./traefik:/etc/traefik
- ./docker:/etc/docker
whoami:
image: "containous/whoami"
container_name: "whoami"
这是我的 traefik.toml:
[entryPoints]
[entryPoints.web]
address = ":80"
[providers]
[providers.file]
filename = "/etc/docker/dynamic_conf.toml"
[providers.docker]
exposedByDefault = false
[api]
insecure = true
这是我的dynamic_conf.toml:
[http]
[http.routers]
[http.routers.whoami]
rule = "Host(`whoami.localhost`)"
entrypoints = "web"
service = "whoami"
但是当我构建图像并运行它时,我收到错误:
Cannot start the provider *file.Provider: toml: cannot load TOML value of type string into a Go slice
找不到原因,搜了一下,改了
filename = "/etc/docker/dynamic_conf.toml"
到
filename = ["/etc/docker/dynamic_conf.toml"]
最佳答案
entryPoints
是一个 slice ,而不是字符串。
我不确定您是否需要更改大小写,但您肯定需要将其更改为 slice ,如下所示:
entryPoints = ["web"]
您可以在this page上找到它的示例在“优先级”>“设置优先级 - 使用文件提供程序”下。
此外,filename 属性是一个字符串,因此请保留它之前的样子。请参阅this link :
filename = "/etc/docker/dynamic_conf.toml"
关于go - 无法将 traefik 与动态配置文件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58620310/