我以docker-compose
开始一些docker容器,并期望traefik
根据容器的名称和域自动创建Host
规则。这就是我过去一直拥有的。
通过traefik.toml
在domain = "example.com"
中设置了域,并且规则模板保留为默认值。
问题在于主机规则的名称中包含.docker.
元素部分:
{
"docker":{
"backends":{
"backend-traefik-docker":{
"servers":{
"server-docker-traefik-1-b8a648f1d4e2b692fb0a888a6a920124":{
"url":"http://172.22.0.4:80",
"weight":1
}
},
"loadBalancer":{
"method":"wrr"
}
},
"backend-web-docker":{
"servers":{
"server-docker-web-1-5d8b13ed7d68cab587a76ca7083edea3":{
"url":"http://172.22.0.3:80",
"weight":1
}
},
"loadBalancer":{
"method":"wrr"
}
},
"backend-whoami-docker":{
"servers":{
"server-docker-whoami-1-b63b00b9e018119bfbb2dee19bcc8f9e":{
"url":"http://172.22.0.2:80",
"weight":1
}
},
"loadBalancer":{
"method":"wrr"
}
}
},
"frontends":{
"frontend-Host-nginx-docker-localhost-1":{
"entryPoints":[
"http"
],
"backend":"backend-web-docker",
"routes":{
"route-frontend-Host-nginx-docker-localhost-1":{
"rule":"Host:nginx.docker.localhost"
}
},
"passHostHeader":true,
"priority":0,
"basicAuth":null
},
"frontend-Host-traefik-docker-example-com-2":{
"entryPoints":[
"http"
],
"backend":"backend-traefik-docker",
"routes":{
"route-frontend-Host-traefik-docker-example-com-2":{
"rule":"Host:traefik.docker.example.com"
}
},
"passHostHeader":true,
"priority":0,
"basicAuth":null
},
"frontend-Host-whoami-docker-example-com-0":{
"entryPoints":[
"http"
],
"backend":"backend-whoami-docker",
"routes":{
"route-frontend-Host-whoami-docker-example-com-0":{
"rule":"Host:whoami.docker.example.com"
}
},
"passHostHeader":true,
"priority":0,
"basicAuth":null
}
}
}
}
例如,Host:whoami.docker.example.com
实际上应该是Host:whoami.example.com
(没有.docker.
来自某个地方)。
配置文件非常混合(我在defaultRule
中尝试使用traefik.toml
和不使用# cat docker-compose.yaml
version: '3'
services:
traefik:
image: traefik
ports:
- "80:80"
- "8082:8080"
volumes:
- $PWD/traefik/traefik.toml:/etc/traefik/traefik.toml
whoami:
image: containous/whoami
web:
image: nginx
# cat traefik/traefik.toml
debug = true
[entryPoints]
[entryPoints.http]
address = ":80"
[docker]
endpoint = "tcp://192.168.10.2:2375"
domain = "example.com"
defaultRule = "Host(`{{ normalize .Name }}`)"
watch = true
exposedByDefault = true
usebindportip = true
swarmMode = false
swarmModeRefreshSeconds = 15
network = "web"
[api]
dashboard = true
):
label
注意:我知道我可以在service
(即docker-compose.yaml
)的'traefik.frontend.rule=Host:thecontainername.example.com'
定义中添加一个declare @outgoings_weight table(space_type varchar(max), w numeric(2,1));
declare @rental_weight table(space_type varchar(max), space_quality varchar(max), campuse_cost varchar(max), w numeric(2,1));
,但我想设置默认行为。