Define host and path frontend rule for Traefik

Viewed 25262

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?

2 Answers

Update: Traefik v2

If the path does not work

Host(`domain.com`) && Path(`/path`) 


does not work, use PathPrefix

Host(`domain.com`) && Pathprefix(`/path`)

Ref

Related