traefik v1 与 v2 版本的配置差别很大,属于破坏是更新,要注意的是 static 配置与 dynamic 配置分为两个文件
docker-compose.yml 配置
version: '3'
services:
reverse-proxy:
image: traefik:v2.0.0
container_name: "traefik"
ports:
- 80:80
- 8000:8000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik.toml:/traefik.toml
# - /traefik/acme.json:/acme.json
# - /var/log/traefik:/var/log
- ./dynamic_conf.toml:/dynamic_conf.toml
whoami:
# A container that exposes an API to show its IP address
image: containous/whoami
labels:
# 声明公开此容器访问
- "traefik.enable=true"
# 服务将响应的域
- "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"
# 只允许来自预定义的入口点“web”的请求
- "traefik.http.routers.whoami.entrypoints=web"
traefik.toml 的配置
## traefik.toml
## Static configuration
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.https]
address = ":443"
[entryPoints.traefik]
address = ":8000"
[providers]
[providers.docker]
exposedByDefault = false
[providers.file]
filename = "dynamic_conf.toml"
# watch = true
[retry]
[api]
dashboard = true
insecure = true
#debug = true
[ping]
dynamic_conf.yml 的配置
## dynamic_conf.toml
## Dynamic configuration
[http.routers.my-api]
entryPoints = ["traefik"]
rule = "PathPrefix(`/dashboard`) || PathPrefix(`/api`)"
service = "api@internal"
middlewares = ["auth"]
[http.middlewares.auth.basicAuth]
users = [
"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
]
网友评论