技能标识:initial-traefik
Initialize and configure Traefik reverse proxy with Docker. Install Traefik, configure Docker Compose, set up service routing via path prefix or host-based routing, enable features like dashboard metrics logging tracing, configure Dashboard access via nip.io or path prefix
使用 Docker Compose 初始化并配置 Traefik v3 反向代理,用于服务路由和负载均衡。
bash
mkdir -p ~/.docker/compose
cd ~/.docker/compose
使用 assets/docker-compose.yml 作为模板。关键配置如下:
yaml
services:
traefik:
image: traefik:v3.0
container_name: traefik
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik-dynamic.yml:/etc/traefik/dynamic.yml:ro
command:
- --api=true
- --api.dashboard=true
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --providers.file.directory=/etc/traefik
- --providers.file.watch=true
- --entrypoints.web.address=:80
- --accesslog=true
- --metrics.prometheus=true
使用 assets/traefik-dynamic.yml 作为服务路由模板。
bash
docker compose up -d
bash
for container in
docker network connect compose_default $container
done
通过 http://
yaml
http:
routers:
n8n:
rule: PathPrefix(/n8n)
service: n8n
entryPoints:
- web
middlewares:
- n8n-stripprefix
middlewares:
n8n-stripprefix:
stripPrefix:
prefixes:
- /n8n
services:
n8n:
loadBalancer:
servers:
- url: http://n8n:5678
访问地址:http://192.168.9.192/n8n
通过 http://
yaml
http:
routers:
n8n:
rule: Host(n8n.192.168.9.192.nip.io)
service: n8n
entryPoints:
- web
services:
n8n:
loadBalancer:
servers:
- url: http://n8n:5678
访问地址:http://n8n.192.168.9.192.nip.io
直接在 docker-compose.yml 的标签中配置路由:
yaml
services:
traefik:
labels:
- traefik.enable=true
- traefik.http.routers.dashboard.rule=Host(traefik.192.168.9.192.nip.io)
- traefik.http.routers.dashboard.service=api@internal
- traefik.http.routers.dashboard.entrypoints=web
完整功能列表及配置请参见 references/features.md。
services:
myservice:
loadBalancer:
servers:
- url: http://
Traefik 会自动重新加载配置。
bash
docker logs traefik | grep -E router|error
docker exec traefik wget -q -O - http://localhost:8080/api/http/routers
bash
docker restart traefik
以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:
帮我安装 SkillHub 和 initial-traefik-1776273002 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 initial-traefik-1776273002 技能
skillhub install initial-traefik-1776273002
文件大小: 7.83 KB | 发布时间: 2026-4-16 16:02