简体   繁体   English

如何在 docker-compose 文件中引用 traefik v2 的自签名 SSL 证书?

[英]How do I reference a self-signed SSL certificates for traefik v2 in a docker-compose file?

There is very limited documentation for referencing self-signed certificates for Træfik v2 in the docker-compose YAML file. docker-compose YAML 文件中用于引用 Træfik v2 的自签名证书的文档非常有限。 Here is how you can do it for Let's Encrypt :以下是Let's Encrypt 的方法:

https://github.com/containous/blog-posts/blob/master/2019_09_10-101_docker/docker-compose-07.yml#L11-L14 https://github.com/containous/blog-posts/blob/master/2019_09_10-101_docker/docker-compose-07.yml#L11-L14

version: "3.3"

services:
  traefik:
    image: "traefik:v2.0.0"
    command:
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --providers.docker
      - --api
      - --certificatesresolvers.leresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
      - --certificatesresolvers.leresolver.acme.email=your@email.com
      - --certificatesresolvers.leresolver.acme.storage=/acme.json
      - --certificatesresolvers.leresolver.acme.tlschallenge=true

But I tried to check the documentation, and I have not seen any way to reference a self-signed certificate in the docker-compose file without having a toml file.但是我尝试检查文档,但我没有看到任何方法可以在没有 toml 文件的情况下在 docker-compose 文件中引用自签名证书。

I have tried this:我试过这个:

version: "3.3"

services:
  traefik:
    image: "traefik:v2.0.0"
    command:
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --providers.docker
      - --api
      - --providers.docker.tls.cert=/etc/certs/server.crt
      - --providers.docker.tls.key=/etc/certs/server.key

But I got the following error:但我收到以下错误:

Failed to retrieve information of the docker client and server host: error during connect: Get https://%2Fvar%2Frun%2Fdocker.sock/v1.24/version: http: server gave HTTP response to HTTPS client" providerName=docker Failed to retrieve information of the docker client and server host: error during connect: Get https://%2Fvar%2Frun%2Fdocker.sock/v1.24/version: http: server gave HTTP response to HTTPS client" providerName=docker

Here are resources I have used that do not provide any way to set up self-signed certificates to enable HTTPS for Træfik v2 in the docker-compose YAML file:以下是我使用的资源,它们不提供任何方式来设置自签名证书以在 docker-compose YAML 文件中为 Træfik v2 启用 HTTPS:

I do see this on this page: https://docs.traefik.io/https/tls/#user-defined我确实在这个页面上看到了这个: https://docs.traefik.io/https/tls/#user-defined

tls:
  certificates:
    - certFile: /path/to/domain.cert
      keyFile: /path/to/domain.key

But it is for file YAML configuration file, and I need to convert this to the docker-compose YAML file equivalent as it is above how they have done it for Let's Encrypt.但它适用于文件 YAML 配置文件,我需要将其转换为 docker-compose YAML 文件,因为它高于他们为 Let's Encrypt 所做的工作。

It seems this is not doable at the moment.目前看来这是不可行的。 Someone posted a very similar question on the Træfik community forum .有人在Træfik 社区论坛上发布了一个非常相似的问题。

The certificates you are passing as flags (providers.docker.tls.cert and providers.docker.tls.key) are useful if Træfik listen to Docker events via a secure TCP endpoint instead of a file socket, which is not what you want. The certificates you are passing as flags (providers.docker.tls.cert and providers.docker.tls.key) are useful if Træfik listen to Docker events via a secure TCP endpoint instead of a file socket, which is not what you want.

It would be cool to have everything configured in a single docker-compose file but unfortunately the self-signed related configuration must be stored in a separate file.在单个 docker-compose 文件中配置所有内容会很酷,但不幸的是,自签名相关配置必须存储在单独的文件中。

Here is an example for the record:这是一个记录示例:

File docker-compose.yml文件docker-compose.yml

traefik:
  image: traefik:v2.1
  command:
    - --entrypoints.web.address=:80
    - --entrypoints.websecure.address=:443
    - --providers.docker=true
    - --providers.file.directory=/etc/traefik/dynamic_conf
    - --providers.file.watch=true
  ports:
    - 80:80
    - 443:443
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro
    - ./certs/:/certs/:ro
    - ./traefik.yml:/etc/traefik/dynamic_conf/conf.yml:ro

web:
  image: nginx:1.17.8-alpine
  labels:
    # http with redirection
    - traefik.http.middlewares.redirect-middleware.redirectscheme.scheme=https
    - traefik.http.routers.web-router.entrypoints=web
    - traefik.http.routers.web-router.rule=Host(`your-domain.net`)
    - traefik.http.routers.web-router.middlewares=redirect-middleware
    # https
    - traefik.http.routers.websecure-router.entrypoints=websecure
    - traefik.http.routers.websecure-router.tls=true
    - traefik.http.routers.websecure-router.rule=Host(`your-domain.net`)

File traefik.yml文件traefik.yml

tls:
  certificates:
    - certFile: /certs/awx.afone.priv.crt
      keyFile: /certs/awx.afone.priv.key

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM