Hi All,
2-day-old newbie to traefik, needing help with what istm is a basic first docker provider config.
I've tried searching through the docs, but just can't figure out how to do what I'm after.
I'd like to have docker containers like
- app1
- app2
- app3
And have these accessed through traefik via the urls
http://app.mydomain.com/app1
http://app.mydomain.com/app2
http://app.mydomain.com/app3
However the apps themselves don't like these extra paths, so I'd like strip the prefix from the access paths so the apps don't see them.
If I access http://app.mydomain.com/app2/foo
I'd like container app2
to get the request http://{container.ip.addr}}/foo
As a repro, the config I do know partially works is having the following in my traefik docker-compose.yml
:
version: "3"
services:
traefik:
image: "traefik:v2.5.4"
command:
- --entrypoints.web.address=:80
- --providers.docker=true
- --api
- --api.insecure=true
- --api.dashboard=true
- --providers.file.directory=/etc/traefik/dynamic
- --providers.docker.defaultRule=Host(`app.mydomain.com`) && PathPrefix(`/{{ index .Labels "com.docker.compose.service" }}`)
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
app1:
image: containous/whoami:v1.3.0
app2:
image: containous/whoami:v1.3.0
app3:
image: containous/whoami:v1.3.0
Having added 127.0.0.1 app.mydomain.com
to \etc\hosts
, doing a curl to http://app.mydomain.com/app{1,2,3}/foo
this routes to the correct service, but the request path they receive is /app1/foo
, /app2/foo
, /app3/foo
whereas I'd like them all to get /foo
.
I feel like I'd like to be able to add the following to the command line params in the docker-compose:
--providers.docker.middleware.default-stripprefix.stripprefix.prefixes=`/{{ index .Labels "com.docker.compose.service" }}`
but it doesnt work (error: command traefik error: failed to decode configuration from flags: field not found, node: middleware
)
I can't find any docs that indicate what the correct commandline param(s) might be.
I'm thinking it might need to be in a dynamic config file (I've seen that too messing with tls config, but want to keep all that out of the repro at this stage!) but again can't seem to find what the correct config would be for a default rule middleware.
I can find lots of refs (and get it working) where I have to specify it in labels on each container, but I'd prefer just to default this out with one-time entries in the traefik config itself.
I've been bashing my head against this for 2 days now. I've tried searching the docs site, this community and the googleverse but without luck. It seems like such a "101" config to me!
Please would someone help me not only solve my issue but teach me how I could have found the solution myself in the docs site.
TIA