I am trying to use Traefik to deploy proxy multiple applications in my Docker Swarm mode cluster.
I have got it so that it proxies a named Host but I want it to proxy on a named Host and Path, but I cannot work out the labels I need to use.
This is the docker service
command I am using:
docker service create \
\
--label "traefik.port=9000" \
--label "traefik.docker.network=traefik-net" \
--label "traefik.frontend.rule=Host:`hostname -f`" \
--label="traefik.backend=portainer" \
\
--constraint "node.role == manager" \
-p 9000:9000 \
--mount "type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock" \
--name portainer \
portainer/portainer
If the host is dummy.localhost
then I am able to hit the portainer app on http://dummy.localhost
. However I want to modify it so that I have to use http://dummy.localhost/portainer
.
I have seen that there are ways to do this when using a toml file for Traefik, but I am using watch mode and labels on the docker services I deploy.
How can I combine multiple front end rules in my labels so that this (and any other) application can be proxied on a hostname and a path?
A frontend consists of a set of rules that determine how incoming requests are forwarded from an entrypoint to a backend. Rules may be classified in one of two groups: Modifiers and matchers.
Rules are a set of matchers configured with values, that determine if a particular request matches specific criteria. If the rule is verified, the router becomes active, calls middlewares, and then forwards the request to the service.
Priority. To avoid path overlap, routes are sorted, by default, in descending order using rules length. The priority is directly equal to the length of the rule, and so the longest length has the highest priority.
Yes, it is operating slower then Nginx, but adding Traefik to project is so simple that you can win any deadlines, especially if you are using Docker/Compose/K8S. It also already has internal analytics.
If you want multiple rules to apply in order for a routing decision to become effective, separate them by semicolon. For instance:
Host: <your host rule>; PathPrefixStrip: /portainer
What the above means is: If the host and path prefix match, Traefik will route requests to the associated backend(s) (and strip off the specified path prefix prior to forwarding). This even works when defined inside a label.
See the frontend documentation for details.
Host(`domain.com`) && Path(`/path`)
See the docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With