1

Is it possible to route subfolders to different containers?

For example http://localhost/wordpress would load Wordpress and http://localhost/drupal would load, well, Drupal.

I know I could get away with using subdomain. But here, it's for a testing environment where creating subdomain every time may be a waste of time

EDIT: docker-compose.yml after the first answer

version: '3'

services:
  reverse-proxy:
    image: traefik:2.0
    command: --api.insecure=true --providers.docker
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  wordpress:
    image: wordpress
    labels:
      - "traefik.http.routers.whoami.rule=Host(`localhost`) && Path(`/wordpress`)"
  drupal:
    image: drupal
    labels:
      - "traefik.http.routers.whoami.rule=Host(`localhost`) && Path(`/drupal`)"
Axiol
  • 173
  • 1
  • 2
  • 8

2 Answers2

2

Looking at the config you've posted after updating it based on @Zoredache's answer, you're almost there.

The only thing you should need to change to make everything work, is the name of the routers.

You've got traefik.http.routers.whoami.rule as the label name for both services, so Traefik is just using overwriting the routing for whichever service comes up last.

You should name each label uniquely, so that they don't overlap.

For example:

version: '3'

services:
  reverse-proxy:
    image: traefik:2.0
    command: --api.insecure=true --providers.docker
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  wordpress:
    image: wordpress
    labels:
      - "traefik.http.routers.wordpress.rule=Host(`localhost`) && Path(`/wordpress`)"
  drupal:
    image: drupal
    labels:
      - "traefik.http.routers.drupal.rule=Host(`localhost`) && Path(`/drupal`)"

Notice how each rule now is named for the service that it's looking to serve (wordpress, and drupal).

GregL
  • 9,370
  • 2
  • 25
  • 36
1

Yes

Assuming you are using 2.0, you need to set your Rule to include a Path component under your router.

The example from the docs.

rule = "(Host(`containo.us`) && Path(`/traefik`))"

Also the 1.7 docs where this is done on a frontend.

Zoredache
  • 130,897
  • 41
  • 276
  • 420
  • Thanks, that seems to work fine. Until I bring a second container up. When I bring a second one up, every path get redirect to just `localhost`. I have to kill everything and just start one again for it to work back (I edited my question with the state of my `docker-compose.yml`) – Axiol Oct 18 '19 at 19:43
  • I haven't done much with traefik v2 yet, but I suspect I would enable the debug logs, and the dashboard and look for more information in the logs/dashboard – Zoredache Oct 18 '19 at 20:34