Introduce
近期由于一些未知原因,在拉取 Docker 镜像或者是使用 docker compose up -d 安装时,总有一些源访问不到从而导致安装失败。因此需要使用 Clash 进行代理。然而常见的 CFW 是需要图形化窗口的,而服务器上没有图形化窗口,因此需要使用其它的电脑做代理,极其不便。而本文的 Docker Clash 很好的解决的这个痛点。
警告⚠️
Clash 服务是一个网络代理工具,工具仅可用于正常的软件开发使用,严禁将其用于任何非法用途。
1. 安装 Docker Clash
在 opt 目录下新建一个 clash-config 文件夹,之后在里面新建一个名为 config.yaml 的文件并粘贴下面的内容。这个文件是保存订阅信息和 Clash 配置信息的文件。也可以将你电脑本机的 Clash 配置文件复制进去,但必须将名称改为 config.yaml
# port of HTTP
port: 7890
# port of SOCKS5
socks-port: 7891
# redir port for Linux and macOS
# redir-port: 7892
allow-lan: true
# Only applicable when setting allow-lan to true
# "*": bind all IP addresses
# 192.168.122.11: bind a single IPv4 address
# "[aaaa::a8aa:ff:fe09:57d8]": bind a single IPv6 address
# bind-address: "*"
# rule / global / direct (default is rule)
mode: rule
# set log level to stdout (default is info)
# info / warning / error / debug / silent
log-level: info
# RESTful API for clash
external-controller: 0.0.0.0:9090
使用 Host 模式安装。
sudo docker run -d --name clash \
--restart unless-stopped \
--log-opt max-size=1m \
--network host \
-v /opt/clash-config:/root/.config/clash \
dreamacro/clash
2. 安装 Clash Web UI
在 Docker 中安装 Web UI 用于管理 Clash 服务。
docker run -d --name ClashWebUI \
-p 1234:80 \
--restart unless-stopped \
haishanh/yacd
打开之后,填写 Clash 的 IP 地址 + Config.yaml 中的 external-controller 部分的端口号。如果有 Secret 的话也需要填写。之后就可以从 Web 管理服务器上的 Clash 了。
3. Docker 代理配置
在 /etc/docker/daemon.json 中添加代理
{
"proxies": {
"http-proxy": "http://127.0.0.1:7890",
"https-proxy": "http://127.0.0.1:7890"
},
}
之后重启服务
sudo systemctl restart docker
Docker 就可以使用 Clash 代理了。
参考
https://hub.docker.com/r/dreamacro/clash
https://wayjam.me/posts/docker-clash-with-tproxy/#%E7%BB%88%E7%AB%AF%E4%BB%A3%E7%90%86
评论区