Synology Docker installs and runs Clash and automatically renews subscriptions

Original link: https://fugary.com/?p=363

​ Recently I bought Clash ‘s airport subscription address. I found that Clash ladder is more convenient to access the network, but it needs to install the corresponding software on each computer or device, which is relatively troublesome. In fact, the Allow LAN mode can be enabled in the local area network, other Devices can be accessed through this proxy, just as there is a long-running NAS on the local LAN that can act as a long-term proxy through it.

Note: This article does not cover how to purchase a subscription address, please solve it yourself.

Prepare the Clash configuration file

Add a config.yaml file, which needs to be uploaded to Synology’s /docker/clash/config.yaml . This yaml file can be copied from the Clash of the local computer:

image-20220703164622625

Note: Only config.yaml不used here, not config.yml . Some information can be modified appropriately, or not modified:

 # Port of HTTP(S) proxy server on the local end(默认) port: 7890 # Port of SOCKS5 proxy server on the local end(默认) socks-port: 7891 # 开启局域网代理,这个要配置true allow-lan: true #UI监听端口,可以改成0.0.0.0:9090,改后可以通过ui界面访问external-controller: 0.0.0.0:9090

After the configuration file is ready and uploaded to Synology, you can start.

Docker install Clash image

Enter the Synology Docker suite, search for crash, you can see dreamacro/clash clash double-click to download it.

image-20220703140044584

Corresponding open source address:

GitHub address: https://github.com/Dreamacro/clash

Docker address: https://registry.hub.docker.com/r/dreamacro/clash/

Reference configuration file: https://github.com/Dreamacro/clash/wiki/configuration

Configure the Clash container

Find the image you just downloaded, now you can start configuring the Clash container, click [Start], and then the next step:

image-20220703142612130

Configure the port. It is best to map the currently open ports. Configure the local port according to the actual situation. The container port is fixed:

image-20220703143036183

Then map the configuration file, the local configuration file /docker/clash/config.yaml is mapped to the container’s /root/.config/clash/config.yaml

image-20220703143230426

The configuration is complete and can be started.

In fact, the clash agent is already available, but for the convenience of viewing, you can use the UI tool to check it again.

Using the UI interface

Online UI interface: http://yacd.haishan.me/

Enter the corresponding address, such as local: http://192.168.31.126:9090

You can also install a UI container by yourself, named: haishanh/yacd, download and install after searching. Generally, you can use the online version without installing docker version of the ui interface.

image-20220703165059849

After downloading, enter the startup configuration and configure automatic restart:

image-20220703165339662

Configure the port:

image-20220703165555219

Startup is complete.

Visit: http://192.168.31.126:9080/, add the address of the crash service

image-20220703170428513

After entering, you can see the subscription information of crash:

image-20220703170538462

UI installation configuration is complete.

proxy use

Taking an iOS phone as an example, in the [Wireless LAN] setting, the information icon on the right side of the connected WIFI :

Configure HTTP proxy:

image-20220703170819896

Then you can try to visit https://google.com to test it.

auto update

At present, this mode of operation cannot automatically update the agent. You can consider using a scheduled task to update, write a scheduled task script, and store /docker/clash/reload-clash.sh :

Note: If the subscription address is not in yml format when opened with a browser, this method cannot be used. You can try adding parameters after the url : ?target=clash or clash=1 to see if the yml data can be converted.

 # 下载节点配置文件,根据实际的订阅地址填写wget -O config.yaml https://xxxxxx # external-controller地址为0.0.0.0:9090,方便UI访问sed -i 's/127.0.0.1:9090/0.0.0.0:9090/g' config.yaml # 重启clash 容器,名字为实际的容器名字docker container restart dreamarco-clash1

To configure Synology timed tasks, go to [Control Panel] -> [Task Scheduler]:

image-20220703175703733

Then add a task, [User-defined script] task, and configure the name, etc.

chrome_NvhlmHcwVn

Configure running frequency:

chrome_zl24Y9FoL0

Configure the run script bash /volume1/docker/clash/reload-clash.sh :

chrome_MLTqofS0wr

Need to pay attention to the path, the full path is to include /volume1

You can run a test first to see.

At this point, the configuration is complete.

common problem

Running the script prompts no permission to run docker:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post “ http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/dreamacro-clash1 /restart “: dial unix /var/run/docker.sock: connect: permission denied

You can try to modify the script and put the password required by sudo in:

sudo -S means that sudo reads passwords from standard input STDIN rather than from the terminal.

 echo "YourPWD" | sudo -S docker container restart dreamarco-clash1

This article is reprinted from: https://fugary.com/?p=363
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment