Search code examples
gotraefik

can not use traefik with dynamic configuration file


I'm trying to learn and use traefik. here is my 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"

and here is my traefik.toml:


[entryPoints]
  [entryPoints.web]
    address = ":80"

[providers]
  [providers.file]
    filename = "/etc/docker/dynamic_conf.toml"
  [providers.docker]
    exposedByDefault = false

[api]
  insecure = true

and this is my dynamic_conf.toml:

[http]
    [http.routers]
        [http.routers.whoami]
            rule = "Host(`whoami.localhost`)"
            entrypoints = "web"
            service = "whoami"

but when i build the image and run it, I get an error:

Cannot start the provider *file.Provider: toml: cannot load TOML value of type string into a Go slice

Screenshot: traefik errors

I couldn't find out the reason, I searched and I changed

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

to

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

Solution

  • entryPoints is a slice, not a string.

    I'm not sure if you need to change the capitalization, but you definitely need to change it to a slice, like this:

    entryPoints = ["web"]
    

    You can find an example for it on this page under Priority > Set priorities -- using the File Provider.

    Also, the filename property is a string, so leave it as it was before. See this link:

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