1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# 创建一个新服务
$ cat test-service.yaml
version: '3'
services:
whoami:
image: containous/whoami
labels:
- "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"
# 创建服务
$ docker-compose -f test-service.yaml up -d whoami
Pulling whoami (containous/whoami:)...
latest: Pulling from containous/whoami
6f3614cb05a5: Pull complete
# 查看新创建的服务
$ docker-compose -f test-service.yaml ps
Name Command State Ports
--------------------------------------------
20190927_whoami_1 /whoami Up 80/tcp
# 再次查看traefik中的路由信息(就会发现服务自动加载进去了)
# 其实有点儿类似kong 的路由,只是traefik会自动监听docker的事件
$ curl -s "http://localhost:8080/api/rawdata" | python -m json.tool
{
"routers": {
"reverse-proxy-20190927@docker": {
"rule": "Host(`reverse-proxy-20190927`)",
"service": "reverse-proxy-20190927",
"status": "enabled",
"using": [
"http",
"traefik"
]
},
"whoami@docker": {
"rule": "Host(`whoami.docker.localhost`)",
"service": "whoami-20190927",
"status": "enabled",
"using": [
"http",
"traefik"
]
}
},
"services": {
"reverse-proxy-20190927@docker": {
"loadBalancer": {
"passHostHeader": true,
"servers": [
{
"url": "http://172.21.0.2:80"
}
]
},
"serverStatus": {
"http://172.21.0.2:80": "UP"
},
"status": "enabled",
"usedBy": [
"reverse-proxy-20190927@docker"
]
},
"whoami-20190927@docker": {
"loadBalancer": {
"passHostHeader": true,
"servers": [
{
"url": "http://172.21.0.3:80"
}
]
},
"serverStatus": {
"http://172.21.0.3:80": "UP"
},
"status": "enabled",
"usedBy": [
"whoami@docker"
]
}
}
}
|