Define host interface rule and paths for Traefik
I am trying to use Traefik to deploy multiple proxy applications on my cluster of Docker Swarm modes.
I have it so that it proxies a named host, but I want its proxy on the named host and path, but I cannot parse the labels I need to use.
This is the command docker service
I'm 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 host dummy.localhost
then I can push the portainer app to http://dummy.localhost
. However, I want to change it to use http://dummy.localhost/portainer
.
I have seen there are ways to do this when using the toml file for Traefik, but I am using view and label mode for the docker services I am deploying.
How can I combine multiple front end rules in my labels so that this (and any other) application can be proxied to the hostname and path?
source to share
If you want to apply multiple rules to make your routing decision effective, separate them with semicolons. For example:
Host: <your host rule>; PathPrefixStrip: /portainer
What it means: If the host and path prefix match, Traefik will route requests to the associated backend (and remove the specified path prefix before forwarding). It even works if defined inside a label.
See the documentation for the interface for details .
source to share