Traefik不仅仅能作为 ingress 实现 运行在 kubernetes 上,同时也可以直接在 docker上使用
创建网络
docker network create proxy
traefik.yml
api:
dashboard: true
entryPoints:
web:
address: :80
websecure:
address: :443
pilot:
dashboard: false
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
docker-compose.yml
version: '3.7'
services:
traefik:
image: traefik:v2.4
container_name: traefik
restart: always
security_opt:
- no-new-privileges:true
ports:
- 80:80
- 443:443
volumes:
- ./traefik.yml:/traefik.yml:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- proxy
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.traefik-secure.entrypoints=web"
- "traefik.http.routers.traefik-secure.rule=Host(`traefik.lizhe.com`)"
#- "traefik.http.routers.traefik-secure.middlewares=user-auth@file"
- "traefik.http.routers.traefik-secure.service=api@internal"
networks:
proxy:
external: true
设置好 dns,就可以通过设置的 domain 访问了
然后我们来给它添加一个 nginx
docker-compose.yml
version: '3.7'
services:
nginx:
image: nginx
container_name: nginx
restart: always
networks:
- proxy
- default
restart: always
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.nginx-web.entrypoints=web"
- "traefik.http.routers.nginx-web.rule=Host(`nginx.lizhe.com`)"
- "traefik.http.routers.nginx-web.service=nginx-web"
- "traefik.http.services.nginx-web.loadbalancer.server.port=80"
networks:
proxy:
external: true
up 之后就多出了一个 nginx