不能将 traefik 与动态配置文件一起使用

can not use traefik with dynamic configuration file

我正在尝试学习和使用 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

截图:traefik errors

找不到原因,我找了一下,我改了

filename = "/etc/docker/dynamic_conf.toml"

filename = ["/etc/docker/dynamic_conf.toml"]

entryPoints 是切片,不是字符串。

我不确定你是否需要更改大小写,但你肯定需要将其更改为切片,如下所示:

entryPoints = ["web"]

您可以在 this page 的“优先级”>“设置优先级 -- 使用文件提供程序”下找到它的示例。

另外,文件名属性是一个字符串,所以保持原样。见 this link:

filename = "/etc/docker/dynamic_conf.toml"