【问题标题】:traefik v2.2 help using only docker-compose router service entrypointtraefik v2.2 帮助仅使用 docker-compose 路由器服务入口点
【发布时间】:2020-04-14 08:20:43
【问题描述】:

开始学习 docker,traefik 在家玩。

目标:将所有内容放在docker-compose.yml.env 文件中,了解基础知识,并据此发表评论。

想要从traefik.test.local/dashboard而不是test.local:8080获取仪表板,同样应该从traefik.test.local/api访问api。这样就不必考虑端口号了。

/etc/hosts添加行

127.0.0.1       test.local
127.0.0.1       traefik.test.local

docker-compose.yml

version: "3.7"

services:
  traefik:
    # The official v2 Traefik docker image
    image: traefik:v2.2
    # Lets name the container
    container_name: traefik
    command:
      # Enables the web UI
      - "--api.insecure=true" 
      # Tells Traefik to listen to docker
      - "--providers.docker"
    ports:
      # The HTTP port
      - "80: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
    #labels:
      #- "traefik.http.routers.router.rule=Host(`traefik.test.local/dashboard`)"
      #- "traefik.http.routers.router.rule=Host(`traefik.test.local/api`)"
    restart:
      always

无法理解如何从路由器连接到服务。如果我在任何地方错了,也请纠正我。谢谢。

PS:操作系统:kde-neon

【问题讨论】:

    标签: docker-compose traefik


    【解决方案1】:

    您可以使用以下定义来实现这一点,您需要为路由器和服务添加标签,而不仅仅是路由器

    proxy:
        image: traefik:v2.1
        command:
          - '--providers.docker=true'
          - '--entryPoints.web.address=:80'
          - '--entryPoints.metrics.address=:8082'
          - '--providers.providersThrottleDuration=2s'
          - '--providers.docker.watch=true'
          - '--providers.docker.swarmMode=true'
          - '--providers.docker.swarmModeRefreshSeconds=15s'
          - '--providers.docker.exposedbydefault=false'
          - '--providers.docker.defaultRule=Host("traefik.lvh.me")'
          - '--accessLog.bufferingSize=0'
          - '--api=true'
          - '--api.dashboard=true'
          - '--api.insecure=true'
          - '--ping.entryPoint=web'
        volumes:
          - '/var/run/docker.sock:/var/run/docker.sock:ro'
        ports:
          - '80:80'
          - '8080:8080'
        restart:
          always
        deploy:
          labels:
            - traefik.enable=true
            - traefik.docker.network=monitoring
            - traefik.http.services.traefik-dashboard.loadbalancer.server.port=8080
            - traefik.http.routers.traefik-dashboard.rule=Host(`dashboard.traefik.lvh.me`)
            - traefik.http.routers.traefik-dashboard.service=traefik-dashboard
            - traefik.http.routers.traefik-dashboard.entrypoints=web
            - traefik.http.services.traefik-api.loadbalancer.server.port=80
            - traefik.http.routers.traefik-api.rule=Host(`api.traefik.lvh.me`)
            - traefik.http.routers.traefik-api.service=traefik-api
            - traefik.http.routers.traefik-api.entrypoints=web
        logging:
          driver: json-file
          options:
            'max-size': '10m'
            'max-file': '5'
    
    

    如果您使用lvh.me 域,则无需编辑/etc/hosts

    【讨论】:

    • OP 可能需要一些解释。 +1 lvh.me
    • dashboard.traefik.lvh.me 替换为仅traefik.lvh.me => traefik.lvh.metraefik.lvh.me/dashboard 按照要求转到traefik.lvh.me/dashboardapi.traefik.lvh.me 不会去任何显示连接错误的地方。但是,traefik.lvh.me/api/rawdata 显示数据。因此,无法掌握dashboard.traefik.lvh.meapi.traefik.lvh.me的作用。
    • API 域被转发到端口 80,默认情况下这将显示 404 错误,与您访问 HTTP://127.0.0.1:80 时相同。你想在这里实现什么,为什么你甚至需要这个域?
    • 对不起。我问了不好的问题。仪表板和 api 确实从端口 8080 提供服务。我正在学习。希望你能理解。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 2023-04-06
    • 2018-07-29
    • 1970-01-01
    • 2020-11-26
    • 2023-03-23
    • 2022-10-25
    相关资源
    最近更新 更多