Trafik.io作为具有基本身份验证的docker容器

时间:2018-03-26 06:04:39

标签: docker traefik

我想要以下设置:

  • 通过docker compose
  • 将traefik作为docker container运行
  • 隐藏traefik前端后面的仪表板并使用基本身份验证

我有什么?

一个简单的docker-compose.yml:

version: '3'

services:
  traefik:
    image: traefik
    command: --api --docker --docker.domain=domain.com --logLevel=WARN
    networks:
      - webgateway
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.toml:/traefik.toml
    labels:
      - "traefik.frontend.rule=Host:traefik.domain.com"
      - "traefik.port=8080"

networks:
  webgateway:
    driver: bridge

和像这样的traefik.toml:

logLevel = "DEBUG"
defaultEntryPoints = ["http"]
[entryPoints]
    [entryPoints.http]
    address = ":80"
    [entryPoints.https]
    address = ":443"
      [entryPoints.https.tls]
    [entryPoints.traefik]
      [entryPoints.traefik.auth]
        [entryPoints.traefik.auth.basic]
        users = [
         "admin:$SomeSaltedString"
        ]
[api]
  entryPoint = "traefik"
  dashboard = true
[ping]
[docker]
exposedbydefault = false

我希望,由于compose文件中的traefik标签,端口8080的dasboard可以通过traefik.domain.com获得,并且由于traefik配置中的入口点配置而受到基本身份验证的保护。

但是会发生以下情况:

curl -L  http://traefik.domain.com
Bad Gateway%   

这里有什么想法吗?我在某个地方找不到任何日志

2 个答案:

答案 0 :(得分:1)

您必须为Traefik Web UI定义地址。你的traefik.toml应该是这样的:

logLevel = "DEBUG"
defaultEntryPoints = ["http"]
[entryPoints]
    [entryPoints.http]
    address = ":80"
    [entryPoints.https]
    address = ":443"
      [entryPoints.https.tls]
    [entryPoints.traefik]
    address = ":8080"
      [entryPoints.traefik.auth]
        [entryPoints.traefik.auth.basic]
        users = [
         "admin:$SomeSaltedString"
        ]
[api]
  entryPoint = "traefik"
  dashboard = true
[ping]
[docker]
exposedbydefault = false

答案 1 :(得分:1)

您可以只使用标签

  - "traefik.frontend.auth.basic.users=username:$$apr1$$EgzP3sdp$$/AbxxRulwvuoE.3ReJo.i/"

用户名密码对是由生成的 echo $(htpasswd -nb <AUTH-USER> <AUTH-PASS>) | sed -e s/\\$/\\$\\$/g