Search code examples
.netdockerconfigurationtraefikswarm

Traefik won't route path


To test Traefik I have made an app like whoami shown in the Traefik's getting stated documentation that responds with a friendly message to a GET HTTP request to '/' and '/sub' endpoints. I've verified that changing whoami to answer through different paths indeed does works but for some reason, Traefik won't resolve my app even though I've configured it similarly as I did with whoami. I know the first thing that comes to mind is that if I've configured my app the same way as I did with whoami so the problem would be my app but curl does confirm that I can reach my app from Traefik's container so it got me wondering if there's something baked into Traefik that whoami app would work and mine wouldn't. I know that's a silly assumption but I don't see what else my app needs to do besides to respond to an HTTP Get request. You can see the app and how I'm bringing everything up here, just need to see build.sh. Another problem that I did work around it is configuring Traefik in swarm mode which I had to create a Traefik image instead of passing the configuration as an argument. The main configuration shows in the code below and traefik_rp its just an image of traefik with a tom file to set it as sarmMode.

version: '3'

services:
  traefik:
    # The official v2 Traefik docker image
    image: traefik_rp
    # Enables the web UI and tells Traefik to listen to docker
    command: --api.insecure=true --providers.docker
    ports:
      # The HTTP port
      - "80:80"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock
      
  simple_app:
    image: simpleapp
    environment: 
      ASPNETCORE_ENVIRONMENT: Release
    labels:
      - "traefik.http.routers.simple_app_service.rule=Path(`/simpleapp`)"

  whoami:
    # A container that exposes an API to show its IP address
    image: containous/whoami
    labels:
      - "traefik.http.routers.whoami.rule=Path(`/`)"

Best regards.


Solution

  • Traefik doesn't clear the route from the HTTP request and it passes the same way it receives to the application. So your application must answer the same route that it's configured on Traefik. The whoami app probably is programmed to spit out HTTP response regardless of the route being accessed meanwhile the app I programmed only answered to the root ('/') path.