go - 无法将 traefik 与动态配置文件一起使用

标签 go traefik

我正在尝试学习和使用 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 是一个 slice ,而不是字符串。

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

entryPoints = ["web"]

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

此外,filename 属性是一个字符串,因此请保留它之前的样子。请参阅this link :

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

关于go - 无法将 traefik 与动态配置文件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58620310/

相关文章:

docker - Traefik和Nginx在Docker上使用HTTPS/400错误请求

arrays - 如何返回整数字节数组中的最后一个元素

主作用域结束时不调用 goroutine 的延迟

string - 二进制字符串转unicode

kubernetes - 使用多个入口 Controller - 是否可以有一个 "default"?

Gitlab 'Gateway Timeout' 位于 traefik 代理后面

go - defer和命名返回值的顺序是什么

go - 如何在 GO 的 json.RawMessage 中检查 KEY 是否存在?

docker - 无法使用Traefik获得正确的容器IP

docker - Traefik路径路由