【问题标题】:Route to flask and vue containers with traefik使用 traefik 路由到烧瓶和 vue 容器
【发布时间】:2020-03-23 21:30:34
【问题描述】:

我正在尝试调整 this 以使用 traefik v2,但我失败了。所有服务都可以相互交谈并且正在工作,但我无法获得为开发环境工作的路线。我不明白为什么。

docker-compose.dev.command.yml:

version: '3.3'
services:
  proxy:
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      - "--providers.docker.swarmMode=false"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.traefik.address=:8080"

  # backend:
  #   command: bash -c "while true; do sleep 1; done"  # Infinite loop to keep container live doing nothing

  backend:
    command: /start-reload.sh

docker-compose.dev.labels.yml:

version: '3.3'
services:
  proxy:
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.rule=Host(`localhost`)"
      - "traefik.http.routers.traefik.rule=PathPrefix(`/dashboard/`)"
      - "traefik.http.routers.traefik.entrypoints=traefik"

  backend:
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.backend.entrypoints=web"
      - "traefik.http.routers.backend.rule=Host(`localhost`) && PathPrefix(`/redoc`) || PathPrefix(`/api`) || PathPrefix(`/docs`)"

  frontend:
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.frontend.entrypoints=web"
      - "traefik.http.routers.frontend.rule=Host(`localhost`) && PathPrefix(`/`)"

docker-compose.dev.networks.yml:

version: '3.3'
services:
  backend:
    networks:
      default:
        aliases:
          - ${DOMAIN}

我几乎尝试了我能想到的任何东西,但我就是无法让它发挥作用。如果我检查 traefik 仪表板,路由器会在正确的 IP:s 上引用正确的服务,我可以手动尝试以确保它们正常工作,但路由无法正常工作。

我做错了什么?

【问题讨论】:

    标签: docker docker-compose traefik


    【解决方案1】:

    您的定义缺少服务标签,您的后端服务至少需要以下标签

            - traefik.enable=true
            - traefik.http.routers.backend.entrypoints=web
            - traefik.http.services.backend.loadbalancer.server.port=${rplace with service port}
            - traefik.http.routers.backend.rule=Host(`localhost`) && PathPrefix(`/redoc`) || PathPrefix(`/api`) || PathPrefix(`/docs`)
            - traefik.http.routers.backend.service=backend
            - traefik.docker.network=traefik
    

    服务的重置也是如此,你可以阅读更多关于这个here

    【讨论】:

    • 包括 traefik 在内的所有服务都使用运行 docker-compose up 时创建的默认网络。我尝试了您的解决方案,但仍然无法正常工作。 (它没有在 swarm 模式下运行)
    • 你错过了这一行traefik.http.services.backend.loadbalancer.server.port 是不是最重要的一行
    猜你喜欢
    • 2016-01-08
    • 2013-02-04
    • 2023-04-06
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-22
    相关资源
    最近更新 更多