'Middleware does not exist when using local plugin in Traefik

I tried to find answers for this in related posts but i just can´t find it.

I created a local plugin and configured it this way:

traefik.toml

[experimental.localPlugins.myplugin]
moduleName = "test.com/traefik/myplugin"

.traefik.yml

displayName: Do some stuff
type: middleware
import: test.com/traefik/myplugin
summary:do a lot of nice stuffs

testData:
  Headers:
    Foo: Bar

I can see in the logs that the plugin is loaded:

Static configuration loaded {"global":{"checkNewVersion":true},"serversTransport":{"maxIdleConnsPerHost":200},"entryPoints":{"http":{"address":":80","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http":{},"udp":{"timeout":"3s"}},"traefik":{"address":":8080","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http":{},"udp":{"timeout":"3s"}}},"providers":{"providersThrottleDuration":"2s","docker":{"watch":true,"endpoint":"unix:///var/run/docker.sock","defaultRule":"Host(`{{ normalize .Name }}`)","exposedByDefault":true,"swarmModeRefreshSeconds":"15s"}},"api":{"insecure":true,"dashboard":true},"ping":{"entryPoint":"http","terminatingStatusCode":503},"log":{"level":"DEBUG","format":"common"},"accessLog":{"format":"json","filters":{},"fields":{"defaultMode":"keep","headers":{"defaultMode":"drop"}}},"pilot":{"dashboard":true}**,"experimental":{"localPlugins":{"myplugin":{"moduleName":"test.com/traefik/myplugin"}}}}

But when i try to use it like this:

traefik.http.routers.myrouter.middlewares="testplugin-myplugin"

or

traefik.http.routers.myrouter.middlewares="myplugin"

i get an error like:

middleware "testplugin-mypluginn@docker" does not exist

I´m using Traefik 2.5.2 docker image> I tried a few combinations of static and dynamic values without luck :(I´m using Traefik 2.5.2 docker image. I tried a few combinations of static and dynamic values without luck :( Am i missing some configuration?



Solution 1:[1]

You need to reference @file when the middleware is created in a file. Otherwise you can see it is looking for testplugin-myplugin@docker which would imply the middleware is built in the docker rules.

Try something like:

traefik.http.routers.myrouter.middlewares="myplugin@file" 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user18092628