How to direct traefik 2 api site to a subdomain?

Hi guys!

I am trying to get traefik v2 to work after using traefik v1 for quite some time.

I read the post from https://blog.containo.us/traefik-2-0-docker-101-fc2893944b9d so I mainly used it as the base.


version: "3"

services:
  traefik:
    image: "traefik:v2.0.1"
    command:
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --providers.docker
      - --api.insecure
      - --certificatesresolvers.leresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
      - --certificatesresolvers.leresolver.acme.email=example@example.com
      - --certificatesresolvers.leresolver.acme.storage=/acme.json
      - --certificatesresolvers.leresolver.acme.tlschallenge=true
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./acme.json:/acme.json"
    labels:
      - traefik.enable=true
      - traefik.port=8080
      - traefik.frontend.rule=Host:example.example.xyz

  my-app:
    image: containous/whoami:v1.3.0
    labels:
      - "traefik.http.routers.my-app.rule=Host(`whoami.docker.example.xyz`)"
      - "traefik.http.routers.my-app.middlewares=auth"
      - "traefik.http.routers.my-app.entrypoints=websecure"
      - "traefik.http.routers.my-app.tls.certresolver=leresolver"
      - "traefik.http.middlewares.auth.basicauth.users=user:$$apr1$$q8eZFHjF$$Fvmkk//V6Btlaf2i/ju5n/" # user/password

example.example.xyz is replaced from my real site.. but when I tried to go onto the site I just get

Warning: Potential Security Risk Ahead

404 page not found

Are the labels a thing of the past? How to get this work?

Hello @thepenguinthatwants

this is V1 configuration labels:

      - traefik.port=8080
      - traefik.frontend.rule=Host:example.example.xyz

Try this :


version: "3"

services:
  traefik:
    image: "traefik:v2.0.1"
    command:
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --providers.docker
      - --api=true
      - --certificatesresolvers.leresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
      - --certificatesresolvers.leresolver.acme.email=example@example.com
      - --certificatesresolvers.leresolver.acme.storage=/acme.json
      - --certificatesresolvers.leresolver.acme.tlschallenge=true
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./acme.json:/acme.json"
    labels:
      - "traefik.http.routers.dashboard.rule=Host(`traefik.domain.com`)"
      - "traefik.http.routers.dashboard.entrypoints=websecure"
      - "traefik.http.routers.dashboard.tls.certresolver=leresolver"
      - "traefik.http.routers.dashboard.service=api@internal"
  my-app:
    image: containous/whoami:v1.3.0
    labels:
      - "traefik.http.routers.my-app.rule=Host(`whoami.docker.example.xyz`)"
      - "traefik.http.routers.my-app.middlewares=auth"
      - "traefik.http.routers.my-app.entrypoints=websecure"
      - "traefik.http.routers.my-app.tls.certresolver=leresolver"
      - "traefik.http.middlewares.auth.basicauth.users=user:$$apr1$$q8eZFHjF$$Fvmkk//V6Btlaf2i/ju5n/" # user/password
      - "traefik.http.services.my-app.loadbalancer.server.port=80"

In the blog post you can find this file: https://github.com/containous/blog-posts/blob/master/2019_09_10-101_docker/docker-compose-09.yml

Thanks so instead of

      - traefik.frontend.rule=Host:example.example.xyz

it has became?



      - "traefik.http.routers.traefik.rule=Host(`example.example.xyz`)"

Sounds plausible. I also recommend reading traefik documentation, in addition to the blog post to get familiar with further nuances.