Cloudflare使用docker compose部署方式时,特别是在aliyun服务器上进行部署时,需要注意docker pull拉取时的版本,版本较老时,可能会遇到tunnel command参数问题:
WARN0001 The "TUNNEL_TOKEN" variable is not set. Defaulting to a blank string.
导致docker一直重启(设置了restart规则时)。此时token为设置成功,Cloudflare无法捕获tunnel。
遇到这种情况时可以使用指定版本来解决:
XML
services:
cloudflared:
image: cloudflare/cloudflared:1871-81a53555aa82
container_name: cloudflared
restart: unless-stopped
# Logging configuration for Cloudflare Tunnel container
logging:
driver: "json-file" # Use the default json-file logging driver
options:
max-size: "100m" # Maximum log file size before rotation (100 MB)
max-file: "5" # Maximum number of log files to retain (10)
command: tunnel --no-autoupdate run # Command to start the Cloudflare tunnel
# Volume configuration for time synchronization and hosts file persistence
volumes:
- /etc/localtime:/etc/localtime:ro # Synchronize time with the host
# Environment variables for Cloudflare Tunnel
environment:
- TUNNEL_TOKEN=${TUNNEL_TOKEN}
在docker-compose.yml同级文件夹下新建.env文件,内容为:
bash
# 不要加引号
TUNNEL_TOKEN=Your Token
这样就可以顺利启动docker,然后在cloudflare网站中继续设置tunnel相关配置。