Middleware definition causes Docker-defined router to fail with 404 Not Found (v2.4)

This is my test config

version: '3'
    image: traefik/whoami
    restart: always
      traefik.enable: true
      traefik.http.routers.whoami.rule:  Host(`test.mydomain.net`)
      traefik.http.routers.whoami.entrypoints: 'websecure'
      traefik.http.middlewares.corsHeader.headers.accessControlAllowOriginList: '*'
      traefik.http.routers.whoami.middlewares: 'corsHeader'
      traefik.http.middlewares.redirect-to-https.redirectscheme.scheme: 'https'
      traefik.http.routers.whoami.tls: true
      traefik.http.routers.whoami.tls.certresolver: lets-encrypt

As soon as I remove traefik.http.routers.whoami.middlewares: 'corsHeader' it works fine. I also tried using traefik.http.routers.whoami.middlewares: 'corsHeader@docker as indicated in the docs Overview - Traefik | Site | v2.4

I am using Traefik v2.4 but I have also tried with v2.5.

I believe this used to work with Traefik v2.2 or earlier v2.x.

Any ideas?