Traefik 使用记录

⏱2020-03-02 🔖

使用 letsencrypt 与 docker

创建 acme.json, docker-compose.yml, traefik.toml 空文件

docker-compose.yml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
version: '2'

services:

traefik:
image: traefik:1.7
restart: always
ports:
- 80:80
- 443:443
networks:
- web
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /data/traefik/traefik.toml:/traefik.toml
- /data/traefik/acme.json:/acme.json
container_name: traefik

networks:
web:
external: true

traefik.toml

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
debug = false

logLevel = "ERROR"
defaultEntryPoints = ["https","http"]

[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]

[retry]

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "1.io2x.net"
watch = true
exposedByDefault = false

[acme]
email = "[email protected]"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"

设置后端服务使用 traefik 代理

参考: Let’s Encrypt & Docker - Traefik

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
version: '2'

services:
app:
build: ./
restart: always
environment:
STAGE: production
volumes:
- /data/tg-bot/src:/opt/app/src
command:
bash -c "python -u main.py"
networks:
- web
- default
expose:
- "8000"
labels:
- "traefik.docker.network=web"
- "traefik.enable=true"
- "traefik.frontend.rule=Host:tg.1.io2x.net"
- "traefik.port=8000"
- "traefik.protocol=http"

networks:
web:
external: true