Created
November 1, 2019 09:15
-
-
Save hmldd/6ccb1bbc22c81eacead4c5f8b0cb4346 to your computer and use it in GitHub Desktop.
Traefik docker 配置,包含traefik.toml文件、basic auth和grafana配置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
gateway: | |
# 官方最新的 traefik docker 镜像 | |
# 生产环境建议指定镜像版本号 | |
image: traefik:latest | |
# 停止后重新启动 | |
restart: unless-stopped | |
# 静态配置可以通过 traefik.toml 文件设置,command 命令参数移至配置文件 | |
# command: --api --providers.docker | |
ports: | |
# HTTP 端口 | |
- "80:80" | |
volumes: | |
# 绑定 traefik 配置文件 | |
- ./config/traefik/traefik.toml:/etc/traefik/traefik.toml:ro | |
# 绑定 docker.sock 使 traefik 能够监听 docker 事件 | |
- /var/run/docker.sock:/var/run/docker.sock | |
# docker 动态配置使用 labels 设置 | |
labels: | |
# 配置 traefik dashboard 和 api 服务的域名 | |
- "traefik.http.routers.api.rule=Host(`traefik.docker.localhost`)" | |
# 配置 api 服务的中间件 auth | |
- "traefik.http.routers.api.middlewares=auth" | |
# 配置 auth 中间件使用 basicauth 并设置账号密码 | |
# 密码使用 htpasswd 生成 MD5、SHA1 或 BCrypt,生成的密码如果包含 $ 需要在 $ 前添加一个 $ 转义字符 | |
# 生成账号密码可以使用如下的命令: | |
# echo $(htpasswd -nb user password) | sed -e s/\\$/\\$\\$/g | |
- "traefik.http.middlewares.auth.basicauth.users=admin:$$apr1$$zDPJo98m$$XC0zhnLRaYKlXNhoEbUXd/" | |
# 中间件 auth 账号密码验证通过之后路由至 api@internal 服务 | |
- "traefik.http.routers.api.service=api@internal" | |
whoami: | |
image: containous/whoami | |
# 通过 IP 地址或域名提供一个容器的服务 | |
labels: | |
- "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)" | |
# auth 中间件可以共用 | |
- "traefik.http.routers.whoami.middlewares=auth" | |
grafana: | |
image: grafana/grafana:latest | |
# 数据持久化需要设置容器内的grafana user id与当前用户相同,Linux系统通过命令 id -u 获取 | |
user: "501" | |
volumes: | |
- ./config/grafana/grafana.ini:/etc/grafana/grafana.ini | |
- ./data/grafana:/var/lib/grafana | |
labels: | |
- "traefik.http.routers.grafana.rule=Host(`bi.docker.localhost`)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[server] | |
enable_gzip = true | |
[security] | |
admin_user = grafana | |
admin_password = grafana_admin_passwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# traefik 配置,traefik 版本v2.0 参考文档https://docs.traefik.io/ | |
# Notice: traefik.toml 文件仅配置静态(static)参数,docker provider 的动态配置通过docker-compose.yml文件中的 labels 设置 | |
# 日志 | |
[log] | |
# 默认 ERROR,可配置 DEBUG、PANIC、FATAL、ERROR、WARN、INFO | |
level = "DEBUG" | |
# 入口 | |
[entryPoints] | |
[entryPoints.http] | |
address = ":80" | |
# 配置 providers,监听 docker 事件 | |
[providers.docker] | |
endpoint = "unix:///var/run/docker.sock" | |
# 开启 traefik API 和 dashboard 界面 | |
[api] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment