Middleware attached to service

Hello,

i'm using docker compose to setup a service. I need to define a middleware to strip a prefix from all the requests coming to the service. There will be other routers in the future with different hostnames that need to point to this service (that's why i'm trying to attach the middleware to the service and not to the router). This is my compose.yaml:

test:

image: ${TEST_IMAGE_URI}

container_name: test

restart: unless-stopped

env_file: .env-test

logging:

driver: journald

labels:

  • "traefik.enable=true"

  • "traefik.http.routers.test.rule=Host(`test.example.com`)"

  • "traefik.http.routers.test.entrypoints=websecure"

# Middleware to strip prefix

  • "traefik.http.middlewares.test-stripprefix.stripprefix.prefixes=/test"

  • "traefik.http.services.test.loadbalancer.server.port=3000"

  • "traefik.http.services.test.middlewares=test-stripprefix"

When i start the container I get this error in traefik logs: "ERR error="field not found, node: middlewares" container=test providerName=docker"

I'm following this documentation: Traefik HTTP Services Documentation - Traefik

I don't know what's happening

Are you using latest Traefik? I think middlewares on services is a new feature.

Version: 3.6.17
Codename: ramequin
Go version: go1.25.10
Built: 2026-05-11T12:50:08Z
OS/Arch: linux/amd64

Use 3 backticks before and after code/config in posts to make it more readable and preserve spacing, which is important in yaml.

test:
  image: ${TEST_IMAGE_URI}
  container_name: test
  restart: unless-stopped
  env_file: .env-test
  logging:
    driver: journald
  labels:
    - "traefik.enable=true"
    - "traefik.http.routers.test.rule=Host(`test.example.com`)"
    - "traefik.http.routers.test.entrypoints=websecure"
    # Middleware to strip prefix
    - "traefik.http.middlewares.test-stripprefix.stripprefix.prefixes=/test"
    - "traefik.http.services.test.loadbalancer.server.port=3000"
    - "traefik.http.services.test.middlewares=test-stripprefix"

It seems to me the option to use labels to assign a middleware to a service was simply forgotton (doc). As mentioned earlier, middlewares on services is new, it didn't exist in v3.6 (doc). You could create a feature request at Traefik Github.