我使用cloudflare CDN构建traefik。我使用docker container run命令执行由Drone CI执行的docker容器。成功构建docker容器时出现问题,导致子域网关错误。
docker-compose.yml
class R[A] extends M[A]
Traefik.toml
version: '3'
services:
traefik:
image: traefik:latest
container_name: traefik
restart: always
domainname: ${DOMAINNAME}
networks:
- traefik_proxy
ports:
- "80:80"
- "443:443"
- "8080:8080"
environment:
- CF_API_EMAIL=${CLOUDFLARE_EMAIL}
- CF_API_KEY=${CLOUDFLARE_API_KEY}
labels:
- "traefik.enable=true"
- "traefik.backend=traefik"
- "traefik.frontend.rule=Host:monitor.${DOMAINNAME}"
- "traefik.port=8080"
- "traefik.docker.network=traefik_proxy"
- "traefik.frontend.headers.SSLRedirect=true"
- "traefik.frontend.headers.STSSeconds=315360000"
- "traefik.frontend.headers.browserXSSFilter=true"
- "traefik.frontend.headers.contentTypeNosniff=true"
- "traefik.frontend.headers.forceSTSHeader=true"
- "traefik.frontend.headers.SSLHost=example.com"
- "traefik.frontend.headers.STSIncludeSubdomains=true"
- "traefik.frontend.headers.STSPreload=true"
- "traefik.frontend.headers.frameDeny=true"
- "traefik.frontend.auth.basic.users:${HTTP_USERNAME}:${HTTP_PASSWORD}"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /etc/traefik:/etc/traefik
- /etc/docker/shared:/shared
networks:
traefik_proxy:
external:
name: traefik_proxy
我用来运行由Drone执行的Docker容器的命令:
docker容器运行-d --name示例开发--restart = unless- 停止--label“ traefik.backend = example-development”-标签 “ traefik.frontend.rule = Host:subdomain.example.com”-标签 “ traefik.enable = false”-标签“ traefik.port = 6611”-公开6611 cloud.canister.io:5000/用户名/仓库
我的Docker容器正在听http://127.0.0.1:6611
以上代码示例导致错误504网关超时。
答案 0 :(得分:0)
Traefik需要与其连接的容器建立公共网络。在这种情况下,您需要使用--net=traefik_proxy
运行容器。
如果您的容器位于多个网络上,则还需要标签traefik.docker.network=traefik_proxy
来告诉traefik使用哪个网络。