2017-10-02 6 views
0

私はdocker swarmと連携するためにTraefikをセットアップすることができましたし、HTTPリクエストに対してはうまく機能します。しかし、私はのSSLをどのように設定するのかわかりません。のコンテナです。私は証明書を生成するためにletsencryptを使用します。この構成ではドッカーにSSL用の適切なラベルを追加するには?

traefik.toml(部分)

defaultEntryPoints = ["https","http"] 

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

[acme] 
email = "[email protected]" 
storage = "acme.json" 
entryPoint = "https" 
onHostRule = true 
caServer = "https://acme-staging.api.letsencrypt.org/directory" 

ドッキングウィンドウ-compose.yml

version: '3' 
services: 
    web: 
    ... 
    deploy: 
     labels: 
     - "traefik.enable=true" 
     - "traefik.frontend.rule=Host:example.com,www.example.com" 
     - "traefik.docker.network=public" 
     - "traefik.frontend.entryPoints=http" 
     - "traefik.backend=service_web" 

私のコンテナはSSLエントリポイントのセットアップを持っていないので、私のアプリケーションはSSLに達することはありません。 "traefik.frontend.entryPoints"を "https"に変更すると、Letsencryptが呼び出されます(LEはステージングのためにエラーを表示しますが、現時点では問題ありません)。

私の最大の問題は、traffikのTOML設定をdocker-composeラベルに変換する方法がまだわからないことです。たとえば、Traefik docsはエントリポイントを説明していますが、私はさまざまなドメインの下にあるサービスを束ねています。 SSLを持っているものもあれば、SSLを持っていないものもあれば、したがって、httpとhttpsのentryPoints、httpとhttpsのリダイレクトなどをdocker-composeだけで設定できるようにしたいと考えています。

また、docker-composeでエントリポイントを設定できたら、[entryPoints]ブロックをtraefik.tomlに保存する必要がありますか?

答えて

0

アホイ!

要件:ボリュームプラグインをローカルに永続: https://github.com/CWSpear/local-persist Traefikのネットワークが事前に作成する必要があります (そうでない場合は、ボリュームのドライバを変更することがあります):

「ドッキングウィンドウのネットワークでプロキシ-dオーバーレイを作成します」

(1)消防アップTraefik:

version: "3" 

services: 
    traefik: 
    image: traefik 
    #command: --consul --consul.endpoint=consul:8500 
    #command: storeconfig --consul --consul.endpoint=consul:8500 
    networks: 
     - proxy 
    ports: 
     - 80:80 
     - 443:443 
     #- 8080:8080 
    volumes: 
     - /var/run/docker.sock:/var/run/docker.sock 
     - traefikdata:/etc/traefik/ 
    deploy: 
     #replicas: 3 
     replicas: 1 
     placement: 
     constraints: [node.role == manager] 
     update_config: 
     parallelism: 1 
     delay: 45s 
     monitor: 15s 
     restart_policy: 
     condition: on-failure 
     delay: 5s 
     max_attempts: 10 
     window: 60s 

volumes: 
    traefikdata: 
    driver: local-persist 
    driver_opts: 
     mountpoint: /data/docker/proxy 

networks: 
    proxy: 
    external: true 

重要な注意:ACMEを使用しているときに、Traefik(ここでは3のように)をスケールするには、ConsulまたはETCDをConfigの「ストレージ」として使用する必要があります。 Traefikのインスタンスを1つだけ使用する場合は、ConsuleまたはETCDを使用しないでください。 通常のCertificate ETCDの場合&領事は決して必要ありません。

(2)マウントtraefik.toml

logLevel = "WARN" 
debug = false 
defaultEntryPoints = ["http", "https"] 

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

#Letsencrypt 
[acme] 
email = "[email protected]" 
storage = "traefik/acme/account" 
entryPoint = "https" 
onHostRule = true 
onDemand = true 

#[[acme.domains]] 
# main = "yourdomain.at" 
# sans = ["sub1.yourdomain.at", "www.yourdomain.at"] 
#[[acme.domains]] 
# main = "anotherdomain.at" 


#[web] 
#address = ":8080" 

[docker] 
domain = "docker.localhost" 
watch = true 
swarmmode = true 

はコメントのないパートが

必須ではありません(3)任意のサービス

version: '3' 

services: 
    nginx: 
    image: nginx 
    deploy: 
     labels: 
     - "traefik.port=80" 
     - "traefik.docker.network=proxy" 
     - "traefik.frontend.rule=Host:sub1.yourdomain.at" 
     - "traefik.backend=nginx" 
     - "traefik.frontend.entryPoints=http,https" 
     replicas: 1 
    networks: 
     proxy: 
     aliases: 
      - nginx 
    volumes: 
     - html:/usr/share/nginx/html 
    environment: 
     - NGINX_HOST=sub.yourdomain.at 
     - NGINX_PORT=80 
    #command: /bin/bash -c "envsubst </etc/nginx/conf.d/mysite.template> /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" 

networks: 
    proxy: 
    external: true 
    default: 
    driver: overlay 

volumes: 
    html: 
    driver: local-persist 
    driver_opts: 
     mountpoint: /data/docker/html 
を開始

さらにいくつかの例:https://github.com/Berndinox/compose-v3-collection

関連する問題