Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Routing traffic depending on path not domain in docker #706

Closed
mwaaas opened this issue Oct 1, 2016 · 13 comments
Closed

How Routing traffic depending on path not domain in docker #706

mwaaas opened this issue Oct 1, 2016 · 13 comments

Comments

@mwaaas
Copy link

mwaaas commented Oct 1, 2016

I have tried this and its not working

traefik:
  image: traefik
  command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
  ports:
    - "80:80"
    - "8080:8080"
    - "443:443"
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /dev/null:/traefik.toml

machine:
  image: katacoda/docker-http-server
  labels:
    - "traefik.backend=machine-echo"
    - "traefik.frontend.rule=Path:machine-echo./machine"

echo:
  image: katacoda/docker-http-server:v2
  labels:
    - "traefik.backend=echo"
    - "traefik.frontend.rule=Path:echo-echo./echo"
@MBuffenoir
Copy link

very curious about this also, to route traffic to different api version ...

@emilevauge
Copy link
Member

What is not working exactly? Have you tried PathPrefix or PathPrefixStrip rules instead?

@mwaaas
Copy link
Author

mwaaas commented Oct 21, 2016

@emilevauge I have tried using this - "traefik.frontend.rule=Path:echo-echo./echo" I can't see the documentation of "PathPrefix" or "PathPrefixStrip"

@emilevauge
Copy link
Member

@mwaaas
Copy link
Author

mwaaas commented Oct 21, 2016

@emilevauge thanks

Finally got it, it wasn't so obvious from the documentation

--- 


traefik: 
  command: "--web --docker --docker.domain=docker.localhost --logLevel=DEBUG"
  image: traefik
  ports: 
    - "80:80"
    - "8080:8080"
  volumes: 
    - "/var/run/docker.sock:/var/run/docker.sock"
    - "/dev/null:/traefik.toml"
whoami1: 
  image: emilevauge/whoami
  labels: 
    - traefik.backend=whoami
    - "traefik.frontend.rule=Host:whoami.docker.localhost"
whoami2: 
  image: emilevauge/whoami
  labels: 
    - traefik.backend=whoami2
    - "traefik.frontend.rule=Path:/test2/, _/mwas/_"

@mwaaas mwaaas closed this as completed Oct 21, 2016
@mwaaas
Copy link
Author

mwaaas commented Oct 21, 2016

@emilevauge quick question how does one do regex for path in traefik

for example for certain domain I want to forward trafic with this path foo to containerB and the container with path boo to containerC and empty path to containerD

@romainlaisne
Copy link

romainlaisne commented Nov 24, 2016

Hi Guys,

I am trying to do the same but cannot make it work.
I am trying to have mydomain.dev/pma pointing on the phpmyadmin backend:

web:
    image: nginx
    links:
        - app
    volumes_from:
        - app
    volumes:
        - ./web/nginx.conf:/etc/nginx/nginx.conf
    labels:
        - "traefik.backend=web"
        - "traefik.frontend.rule=Host:mydomain.dev"
        - "traefik.port=80"

phpmyadmin:
    image: phpmyadmin/phpmyadmin
    links:
        - db
    labels:
        - "traefik.backend=phpmyadmin"
        - "traefik.frontend.rule=Host:mydomain.dev;Path:/pma"

Anyone having an idea how to solve this?

Thanks

@mwaaas
Copy link
Author

mwaaas commented Nov 24, 2016

@romainlaisne I use this label
"traefik.frontend.rule=PathPrefix:/static/"

@romainlaisne
Copy link

Hi,

I haven't solved my issue yet, but I think that it is not Traefik causing me trouble in the end.
I use Symfony and the routing system is coming on top of everything which I think causes troubles.

Thanks for you help @mwaaas.

@wvdongen
Copy link

@romainlaisne Did you find a solution for you mydomain.dev/pma problem? I've got the same problem.

@wvdongen
Copy link

@romainlaisne Found the answer, use "traefik.frontend.rule=Host:mydomain.dev;PathPrefixStrip:/pma"

@benpetsch
Copy link

benpetsch commented Apr 24, 2018

Solution for me:

I tried something similar to:

    [...]
    labels:
        - "traefik.frontend.rule=PathPrefixStrip:/pma"
        - "traefik.frontend.rule=Host:mydomain.dev"
        [...]

But figured out, this does not work. (Maybe line 1 does overwrite line 2?)

For me worked:

    [...]
    labels:
        - traefik.frontend.rule=Host:mydomain.dev;PathPrefixStrip:/pma
        [...]

@nicechester
Copy link

nicechester commented May 20, 2019

I was looking for path based routing as well and I finally made it working like following referring to all above conversation and official document.

docker run -dit --name xxx \
    --label "traefik.frontend.rule=PathPrefixStrip:/xxx/" \
    --label traefik.backend=xxx \
    myapp

The only caveat is it works with http://mydomain.com/xxx/ but doesn't work without last slash like http://mydomain.com/xxx
I tried to make the rule as PathPrefixStrip:/xxx but no luck.
Thanks!

@traefik traefik locked and limited conversation to collaborators Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants