2017-12-22 15 views
0

Traick을 역 프록시로 사용하여 여러 개의 도커 작성 프로젝트를 사용하고 싶습니다. 문서를 따라 한 후 두 개의 도커 작성 파일을 만들었습니다. 하나는 Traefik 용이고 다른 하나는 2 개의 "우와미 (Whoami)"컨테이너가있는 예제 프로젝트 용입니다.docker-compose가있는 Traefik이 너무 많은 프런트 엔드를 만듭니다.

이 방법은 백엔드에서 효과적이지만 Traefik은 실행중인 컨테이너 당 하나의 프론트 엔드를 생성합니다. 따라서 2 개의 whoami 컨테이너에 대한 프론트 엔드 대신 "frontend-Host-whoami-localhost-0"및 "frontend-Host-whoami-localhost-1"이라는 두 개의 프론트 엔드를 정의했습니다.

트로픽은 whoamer 서비스를 확장 할 경우 (docker-compose.yaml 파일에 정의를 복제하거나 docker-compose scale whoami=10) 중복 프론트 엔드를 만듭니다.

"호스트 : whoami.localhost"규칙에 대해 하나의 프론트 엔드가 필요합니다.이 규칙은 연결된 여러 실행 컨테이너가있는 하나의 백엔드를 가리 킵니다. 어떻게해야합니까?

traefik.toml : (traefik에 대한)

defaultEntryPoints = ["http"] 

[web] 
address = ":8080" 

[entryPoints] 
    [entryPoints.http] 
    address = ":80" 

[docker] 
endpoint = "unix:///var/run/docker.sock" 
domain = "localhost" 

고정 표시기-compose.yaml :

version: "2" 
services: 
    traefik: 
    container_name: traefik 
    image: traefik 
    networks: 
     - webgateway 
    ports: 
     - "80:80" 
     - "8080:8080" 
    volumes: 
     - /var/run/docker.sock:/var/run/docker.sock 
     - ./traefik.toml:/traefik.toml 
    labels: 
     traefik.backend: web 
     traefik.frontend.rule: Host:monitor.localhost 

networks: 
    webgateway: 
    driver: bridge 

WHOAMI/고정 표시기-compose.yaml :

version: "2" 
services: 
    whoami: 
    image: emilevauge/whoami 
    networks: 
     - webgateway 
    labels: 
     traefik.backend: whoami 
     traefik.frontend.rule: Host:whoami.localhost 

    whoami_2: 
    image: emilevauge/whoami 
    networks: 
     - webgateway 
    labels: 
     traefik.backend: whoami 
     traefik.frontend.rule: Host:whoami.localhost 

networks: 
    webgateway: 
    external: 
     name: traefikdocker_webgateway 

답변

0

내가 당신을 가정 그것을 원한다 :

http://example.com/ 
|-> app1 who serve http://example.com/foo 
|-> app2 who serve http://example.com/bar 

은 (예에 의해 PathPrefix 같은) 다른 matcher 사용해야 수행합니다

traefik.frontend.rule: Host:http://example.com/; PathPrefix:/foo 
|-> app1 who serve http://example.com/foo 

traefik.frontend.rule: Host:http://example.com/; PathPrefix:/bar 
|-> app2 who serve http://example.com/bar 

당신이 단지 확장하려는 경우, 당신은 당신의 composefile에 하나 개의 서비스가 필요합니다

traefik.frontend.rule: Host:http://example.com/ 
|-> 10 x app (docker-compose scale app=10)