web-dev-qa-db-ja.com

traefik.tomlファイルがdocker-compose構成によって読み取られないのはなぜですか

私の目標は、基本認証でtraefikフロントエンドを保護することです。

2017-11-14_11:14:24AMにビルドされたTraefikバージョンv1.4.3をDockerコンテナーで実行しています。

私のdocker-compose.ymlファイルは次のようになります:

version: "3"

services:
  proxy:
    image: traefik
    command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
    ports:
      - "80:80"
      - "8081:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ~/git/traefik/traefik.toml:/etc/traefik/traefik.toml
      - ~/git/traefik/.htpasswd:/etc/traefik/.htpasswd

networks:
  default:
    external:
      name: my_nw

Traefik.tomlファイルのWebフロントエンドのセクションは次のようになります。

 ....
 # Enable web configuration backend
 [web]
 address = ":8080"
 [web.auth.basic]
 usersFile = "/etc/traefik/.htpasswd"
 ...

しかし、私のカスタムtraefik.tomlファイルはtraefikによってマウント/読み取りされていないようです-traefikフロントエンドに認証は必要ありません。

デバッグログの出力は次のようになります。

$ docker-compose up
Starting traefik_proxy_1
Attaching to traefik_proxy_1
proxy_1  | time="2017-11-20T07:30:10Z" level=info msg="Using TOML configuration file /etc/traefik/traefik.toml" 
proxy_1  | time="2017-11-20T07:30:10Z" level=info msg="Traefik version v1.4.3 built on 2017-11-14_11:14:24AM" 
proxy_1  | time="2017-11-20T07:30:10Z" level=debug msg="Global configuration loaded {"GraceTimeOut":10000000000,"Debug":false,"CheckNewVersion":true,"AccessLogsFile":"","AccessLog":null,"TraefikLogsFile":"","LogLevel":"DEBUG","EntryPoints":{"http":{"Network":"","Address":":80","TLS":null,"Redirect":null,"Auth":null,"WhitelistSourceRange":null,"Compress":false,"ProxyProtocol":null,"ForwardedHeaders":{"Insecure":true,"TrustedIPs":null}}},"Cluster":null,"Constraints":[],"ACME":null,"DefaultEntryPoints":[],"ProvidersThrottleDuration":2000000000,"MaxIdleConnsPerHost":200,"IdleTimeout":0,"InsecureSkipVerify":false,"RootCAs":null,"Retry":null,"HealthCheck":{"Interval":30000000000},"RespondingTimeouts":null,"ForwardingTimeouts":null,"Docker":{"Watch":true,"Filename":"","Constraints":null,"Trace":false,"DebugLogGeneratedTemplate":false,"Endpoint":"unix:///var/run/docker.sock","Domain":"docker.localhost","TLS":null,"ExposedByDefault":true,"UseBindPortIP":false,"SwarmMode":false},"File":null,"Web":{"Address":":8080","CertFile":"","KeyFile":"","ReadOnly":false,"Statistics":null,"Metrics":null,"Path":"/","Auth":null,"Debug":false,"CurrentConfigurations":null,"Stats":null,"StatsRecorder":null},"Marathon":null,"Consul":null,"ConsulCatalog":null,"Etcd":null,"Zookeeper":null,"Boltdb":null,"Kubernetes":null,"Mesos":null,"Eureka":null,"ECS":null,"Rancher":null,"DynamoDB":null}" 
proxy_1  | time="2017-11-20T07:30:10Z" level=info msg="Preparing server http &{Network: Address::80 TLS:<nil> Redirect:<nil> Auth:<nil> WhitelistSourceRange:[] Compress:false ProxyProtocol:<nil> ForwardedHeaders:0xc420270180} with readTimeout=0s writeTimeout=0s idleTimeout=3m0s" 
proxy_1  | time="2017-11-20T07:30:10Z" level=info msg="Starting provider *docker.Provider {"Watch":true,"Filename":"","Constraints":null,"Trace":false,"DebugLogGeneratedTemplate":false,"Endpoint":"unix:///var/run/docker.sock","Domain":"docker.localhost","TLS":null,"ExposedByDefault":true,"UseBindPortIP":false,"SwarmMode":false}" 
proxy_1  | time="2017-11-20T07:30:10Z" level=info msg="Starting provider *web.Provider {"Address":":8080","CertFile":"","KeyFile":"","ReadOnly":false,"Statistics":null,"Metrics":null,"Path":"/","Auth":null,"Debug":false,"CurrentConfigurations":{},"Stats":{"Uptime":"2017-11-20T07:30:10.282646542Z","Pid":1,"ResponseCounts":{},"TotalResponseCounts":{},"TotalResponseTime":"0001-01-01T00:00:00Z"},"StatsRecorder":null}" 
proxy_1  | time="2017-11-20T07:30:10Z" level=info msg="Starting server on :80" 
proxy_1  | time="2017-11-20T07:30:10Z" level=debug msg="Provider connection established with docker 17.09.0-ce (API 1.32)" 
proxy_1  | time="2017-11-20T07:30:10Z" level=debug msg="Validation of load balancer method for backend backend-proxy-traefik failed: invalid load-balancing method ''. Using default method wrr." 
proxy_1  | time="2017-11-20T07:30:10Z" level=debug msg="Configuration received from provider docker: {"backends":{"backend-proxy-traefik":{"servers":{"server-traefik_proxy_1":{"url":"http://172.19.0.2:80","weight":0}},"loadBalancer":{"method":"wrr"}}},"frontends":{"frontend-Host-proxy-traefik-docker-localhost-0":{"backend":"backend-proxy-traefik","routes":{"route-frontend-Host-proxy-traefik-docker-localhost-0":{"rule":"Host:proxy.traefik.docker.localhost"}},"passHostHeader":true,"priority":0,"basicAuth":[],"headers":{}}}}" 
proxy_1  | time="2017-11-20T07:30:10Z" level=debug msg="Last docker config received more than 2s, OK" 
proxy_1  | time="2017-11-20T07:30:10Z" level=debug msg="Creating frontend frontend-Host-proxy-traefik-docker-localhost-0" 
proxy_1  | time="2017-11-20T07:30:10Z" level=error msg="No entrypoint defined for frontend frontend-Host-proxy-traefik-docker-localhost-0, defaultEntryPoints:[]" 
proxy_1  | time="2017-11-20T07:30:10Z" level=error msg="Skipping frontend frontend-Host-proxy-traefik-docker-localhost-0..." 
proxy_1  | time="2017-11-20T07:30:10Z" level=info msg="Server configuration reloaded on :80" 

私はここからドキュメントに従いました: http://docs.traefik.io/configuration/backends/web/#authentication

セットアップの問題点がわかりません。

8
Ralph

私自身の質問で示された設定が機能しなかった理由は、私のdocker-compose.ymlファイルの 'command'エントリでした:

command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG

このコマンドは、[web]および[docker]設定をtraefik.tomlファイルから上書きします。

したがって、docker-composeを使用してtraefikをdockerコンテナーとして開始する場合は、docker-compose.ymlファイルを使用しないでください。カスタムtraefik.tomlファイルをマウントする場合は、コマンドを含めます。このシナリオでは、すべての設定をtrafik.tomlファイルに配置する必要があります。

したがって、次のdocker-compose.ymlファイルで動作します。

version: "3"

services:
  proxy:
    image: traefik
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - $PWD/traefik.toml:/etc/traefik/traefik.toml
      - $PWD/.htpasswd:/etc/traefik/.htpasswd

networks:
  default:
    external:
      name: my_network

traefik.tomlファイルは、コンテナディレクトリ/etc/traefik/にマウントする必要があることに注意してください。

12
Ralph