Traefick whoami 使用中间件的案例

12 min read
version: '3'

services:
  reverse-proxy:
    # The official v2 Traefik docker image
    image: traefik:v2.9
    # Enables the web UI and tells Traefik to listen to docker
    command: --api.insecure=true --providers.docker
    ports:
      # The HTTP port
      - "8081:80"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock
  whoami:
    # A container that exposes an API to show its IP address
    image: traefik/whoami
    labels:
      # - "traefik.http.middlewares.foo-add-prefix.addprefix.prefix=/foo"
      # - "traefik.http.middlewares.test-auth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/,test2:$$apr1$$d9hr9HBB$$4HxwgUir3HP4EsggP/QNo0"
      - "traefik.http.routers.whoami.rule=Host(`test.docker.localhost`)"
      # - "traefik.http.routers.whoami.middlewares=test-auth"
      - "traefik.http.middlewares.whoami-auth.basicauth.users=user:hashedpassword"
      - "traefik.http.routers.whoami.middlewares=whoami-auth"
      # - "traefik.http.services.whoami.loadbalancer.server.port=80"