Skip to content

Instantly share code, notes, and snippets.

@paneq
Last active December 27, 2024 21:28
Show Gist options
  • Select an option

  • Save paneq/0a3e0bf3a69314f3b283f1c703288d88 to your computer and use it in GitHub Desktop.

Select an option

Save paneq/0a3e0bf3a69314f3b283f1c703288d88 to your computer and use it in GitHub Desktop.

Revisions

  1. paneq renamed this gist Dec 27, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. paneq revised this gist Dec 27, 2024. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    services:
    traefik:
    image: "traefik:v3.2"
    container_name: "traefik"
    command:
    - "--configFile=/etc/traefik/traefik.toml"
    ports:
    - "80:80"
    - "8080:8080"
    volumes:
    - "/var/run/docker.sock:/var/run/docker.sock:ro"
    - "./traefik.toml:/etc/traefik/traefik.toml"
  3. paneq created this gist Dec 27, 2024.
    9 changes: 9 additions & 0 deletions error_example.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    curl -i 'http://localhost:80/foo'

    HTTP/1.1 404 Not Found
    Content-Type: text/plain; charset=utf-8
    X-Content-Type-Options: nosniff
    Date: Fri, 27 Dec 2024 18:38:51 GMT
    Content-Length: 19

    404 page not found
    5 changes: 5 additions & 0 deletions problem.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    I configured Traefik via `/etc/traefik/traefik.toml` in `docker-compose.yml`,
    but all routes were giving me 404 Not Found results. The routing did not even work, nothing was
    forwarded to the right service.

    The culprit turned out to be that `providers` need to be configured.
    4 changes: 4 additions & 0 deletions solution.toml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@

    [providers]
    [providers.file]
    filename = "/etc/traefik/traefik.toml"
    27 changes: 27 additions & 0 deletions traefik.toml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    [log]
    level = "DEBUG"

    [accessLog]

    [api]
    insecure = true
    dashboard = true

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

    [http]
    [http.routers]
    [http.routers.todo]
    rule = "PathPrefix(`/`)"
    service = "todo"
    entryPoints = ["web"]

    [http.services.todo.loadBalancer]
    [[http.services.todo.loadBalancer.servers]]
    url = "http://host.docker.internal:4000"

    [providers] # 404 not found - solution
    [providers.file]
    filename = "/etc/traefik/traefik.toml"