Docker traefik:为一个服务获取尽可能多的前端副本(期望只有一个)

Docker traefik:为一个服务获取尽可能多的前端副本(期望只有一个),docker,docker-compose,label,docker-swarm,traefik,Docker,Docker Compose,Label,Docker Swarm,Traefik,我尝试为swarm集群设置两个docker compose堆栈:一个用于traefik,另一个用于httpd。 它工作得很好,只是:我有一个后端,名为http,有4个副本。但我有4个前端,每个都有相同的路由规则 这是我的docker文件 version: '3.7' networks: default: external: true name: common services: httpd: image: httpd:2.4 # A container tha

我尝试为swarm集群设置两个docker compose堆栈:一个用于traefik,另一个用于httpd。 它工作得很好,只是:我有一个后端,名为http,有4个副本。但我有4个前端,每个都有相同的路由规则

这是我的docker文件

version: '3.7'

networks:
  default:
    external: true
    name: common

services:
  httpd:
    image: httpd:2.4 # A container that exposes an API to show its IP address
    labels:
      traefik.frontend.rule: "Host:httpd.docker.localhost"
      traefik.enable: "true"
      traefik.backend: "http"
    deploy:
      replicas: 4
    networks:
      - default

这是我的traefik.toml

debug = true

################################################################
# API and dashboard configuration
################################################################
[api]

#defaultEntryPoints = ["http", "https", "ws", "wss"]

################################################################
# Web configuration backend
################################################################
[web]
address = ":8080"
[web.auth.basic]
# User: toto | Password: password
users = ["toto:$2y$05$zNs3wc5UPB4su8vbFugVPuKEaLJXMf5Z.9hAI1ulJpBbhbBprfppO"]

################################################################
# Entry-points configuration
################################################################
#[entryPoints]
#  [entryPoints.http]
#    address = ":80"
#    [entryPoints.http.redirect]
#      entryPoint = "https"
#  [entryPoints.https]
#    address = ":443"
#    [entryPoints.https.tls]

################################################################
# Docker configuration backend
################################################################
[docker]
domain = "docker.local"
watch = true
#exposedbydefault = false
这是我得到的

4Frontends
frontend-Host-httpd-docker-localhost-0
Route Rule
Host:httpd.docker.localhost
Entry Points
http
Backend
backend-http
frontend-Host-httpd-docker-localhost-1
Route Rule
Host:httpd.docker.localhost
Entry Points
http
Backend
backend-http
frontend-Host-httpd-docker-localhost-2
Route Rule
Host:httpd.docker.localhost
Entry Points
http
Backend
backend-http
frontend-Host-httpd-docker-localhost-3
Route Rule
Host:httpd.docker.localhost
Entry Points
http
Backend
backend-http
期望:只得到一个前端,而相同的路由规则只到一个后端(因为我只得到一个后端,这对我很好)

got:四个前端,使用相同的路由规则,只到一个后端(因为我只得到一个后端,这对我很好)


我正试着换一种方式。我想从一个服务声明中获得两个数据库服务。但我的是捆绑的,我正试着换一种方式。我想从一个服务声明中获得两个数据库服务。但我的却被捆绑起来了。
4Frontends
frontend-Host-httpd-docker-localhost-0
Route Rule
Host:httpd.docker.localhost
Entry Points
http
Backend
backend-http
frontend-Host-httpd-docker-localhost-1
Route Rule
Host:httpd.docker.localhost
Entry Points
http
Backend
backend-http
frontend-Host-httpd-docker-localhost-2
Route Rule
Host:httpd.docker.localhost
Entry Points
http
Backend
backend-http
frontend-Host-httpd-docker-localhost-3
Route Rule
Host:httpd.docker.localhost
Entry Points
http
Backend
backend-http
logLevel = "DEBUG"
defaultEntryPoints = ["http", "https"]

[api]

[entryPoints]
 [entryPoints.http]
   address = ":80"
   [entryPoints.http.redirect]
     entryPoint = "https"
 [entryPoints.https]
   address = ":443"
   [entryPoints.https.tls]

[docker]
domain = "docker.local"
watch = true
swarmMode = true
#exposedbydefault = false
version: '3.7'

networks:
  default:
    external: true
    name: common

services:
  httpd:
    image: httpd:2.4 # A container that exposes an API to show its IP address
    deploy:
      replicas: 4
      labels:
        traefik.frontend.rule: "Host:httpd.docker.localhost"
        traefik.enable: "true"
        traefik.backend: "http"
    networks:
      - default
version: '3.7'

networks:
  common:
    name: common
    driver: overlay
    attachable: true


services:
  reverse-proxy:
    image: traefik:v1.7.12
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.toml:/etc/traefik/traefik.toml
    networks:
      - common