Files
dock/cl穿透
2026-01-20 22:21:39 +08:00

44 lines
1.3 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 颜色定义
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${GREEN}==== Cloudflare Tunnel Docker 交互安装脚本 ====${NC}"
# 1. 交互式获取 Token
read -p "请输入你的 Cloudflare Tunnel Token: " USER_TOKEN
# 检查输入是否为空
if [ -z "$USER_TOKEN" ]; then
echo -e "${RED}[错误] Token 不能为空!请重新运行脚本并输入有效密钥。${NC}"
exit 1
fi
# 2. 检查并清理同名容器
if [ "$(docker ps -aq -f name=cf-tunnel)" ]; then
echo -e "${YELLOW}[提示] 发现已存在的 cf-tunnel 容器,正在更新...${NC}"
docker rm -f cf-tunnel >/dev/null 2>&1
fi
# 3. 运行 Docker 容器
echo -e "${GREEN}[执行] 正在启动 Cloudflare Tunnel...${NC}"
docker run -d \
--name cf-tunnel \
--restart always \
cloudflare/cloudflared:latest \
tunnel --no-autoupdate run --token "$USER_TOKEN"
# 4. 验证结果
if [ $? -eq 0 ]; then
echo -e "------------------------------------------------"
echo -e "${GREEN}成功Cloudflare Tunnel 已在后台启动!${NC}"
echo -e "容器名称: cf-tunnel"
echo -e "查看日志命令: docker logs -f cf-tunnel"
echo -e "------------------------------------------------"
else
echo -e "${RED}[错误] 容器启动失败,请检查 Docker 是否正常运行。${NC}"
fi