How does traefik handle HTTP requests and responses?

  docker, traefik, url-rewriting

I need help understanding the concept of traefik reverse proxy when using docker.

Assuming I got a webserver (let’s call it service-1) which is usually running on Port 8081.
Without any proxy I would access it this way: http://localhost:8081

According to the traefik docs, the following configuration should me to a access this service by using the a URL in form of http://localhost/my-service:

  image: "service1"
  container_name: "simple-service-1"
    - "traefik.enable=true"
    - "traefik.http.routers.service1.rule=Host(`localhost`) && Path(`my-service`)"
    - "traefik.http.routers.service1.entrypoints=web"
    - ""

Now, what I don’t understand is, how traefik handles responses from the server.

E. g. my server tries to load an e. g. image (or similar). Without the proxy this is done by performing a GET-Request: http://localhost:8081/img/image.jpg.

Now, when using traefik the webserver is not aware of that, thus performing a GET request of /img/image.jpg – which is wrong and not accessible.

If I rewrite the URL using redirectregex, the image is still no accessible: http://localhost/my-service/img/image.jpg (returns a Not found)
And I do not understand why.

I always thought of the concept that an URL in form of http://localhost/my-service/<path> is directly redirected (or stripped) by traefik to http://<docker-internal-ip>:8080/<path> – but apparently this is not the case. What did I miss?

Source: Docker Questions