Here is an example using docker-compose leveraging the addprefix middleware:
version: "3.9"
services:
traefik:
image: traefik:v2.5.2
command:
- --api.insecure
- --log.level=debug
- --providers.docker.exposedByDefault=false
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
ports:
- "8080:8080"
- "80:80"
whoami:
image: traefik/whoami
labels:
- traefik.enable=true
- traefik.http.routers.whoami.rule=Host(`whoami.localhost`)
- traefik.http.routers.whoami.middlewares=add-service-prefix
- traefik.http.middlewares.add-service-prefix.addprefix.prefix=/service
Then, when a request is made with curl like curl http://whoami.localhost/path
the response (which returns the request sent) is the following:
Hostname: fb5a885d9338
IP: 127.0.0.1
IP: 172.20.0.2
RemoteAddr: 172.20.0.3:47414
GET /service/path HTTP/1.1
...
And as expected the requested path is /service/path
.
Is it the behavior you are looking for?