首页 > 解决方案 > traefik 路由到侦听不同端口的容器

问题描述

我有以下 traefik 设置。

路由到whoamiphpunit容器完美运行。但是allure容器想要在端口上运行5050,我不知道如何路由到该端口。

version: '3'

services:
  traefik:
    container_name: traefik
    image: traefik:v2.4
    command:
     - --api.insecure=true
     - --providers.docker
     - --providers.docker.useBindPortIP=true
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  whoami:
    image: traefik/whoami
    labels:
      - "traefik.http.routers.whoami.rule=Path(`/whoami`)"

  phpunit:
    image: nginx
    volumes:
      - /home/ci/phpunit:/usr/share/nginx/html
    labels:
      - "traefik.http.routers.phpunit.rule=PathPrefix(`/phpunit/`)"

  allure:
    image: frankescobar/allure-docker-service
    environment:
      - CHECK_RESULTS_EVERY_SECONDS=3
      - KEEP_HISTORY=1
    volumes:
      - /home/ci/allure/allure_results:/app/allure-results
      - /home/ci/allure/allure_reports:/app/default-reports
    labels:
      - "traefik.http.routers.allure.rule=PathPrefix(`/allure/`)"
      - "traefik.http.services.allure.loadbalancer.server.port=5050"

如果我直接用 - 暴露诱惑容器,5050:5050我可以用http://example.com:5050. 但是使用上面的配置http://example.com/allure/会返回一个 404 页面(allure来自 traefik,而不是来自 traefik)。

我使用--providers.docker.useBindPortIP=truetraefik.http.services.SERVICE.loadbalancer.server.port=5050从这里了解到:Traefik v2 [如何路由到特定端口]

还有更多提示我可以尝试什么吗?

标签: dockerdocker-composereverse-proxytraefik

解决方案


推荐阅读