准备工作
创建clash目录,并在目录下生成config.yaml文件

port: 7890
socks-port: 7891
redir-port: 7892
allow-lan: true
mode: Rule
log-level: warning
external-controller: 0.0.0.0:7070
external-ui: ui
secret: ""
proxies:
    - name: "vmess"
      type: vmess
      server: domain.com
      port: 443
      uuid: d8846cbc-cfe2-48ed-8b2b-6cf161f1dabc
      alterId: 0
      cipher: auto
      udp: false
      tls: true
      skip-cert-verify: false
      servername: domain.com
      network: ws
      ws-opts:
        path: /233blog
        headers:
            Host: domain.com
        early-data-header-name: Sec-WebSocket-Protocol
rules:
  - DOMAIN-SUFFIX,google.com,vmess
  - DOMAIN-KEYWORD,google,vmess
  - DOMAIN,ad.com,REJECT
  - IP-CIDR,192.168.0.0/16,DIRECT
  - IP-CIDR,127.0.0.0/8,DIRECT
  - IP-CIDR6,2620:0:2d0:200::7/32,vmess
  - GEOIP,CN,DIRECT
  - MATCH,vmess
dns:
    enable: true
    listen: 0.0.0.0:1053
    enhanced-mode: redir-host
    nameserver:
        - '114.114.114.114'
        - '223.5.5.5'
    fallback:
        - 'tls://1.1.1.1:853'
        - 'tcp://1.1.1.1:53'
        - 'tcp://208.67.222.222:443'
        - 'tls://dns.google'

用上面的文本替换config.yaml
在当前目录下执行以下命令,跑起docker

mkdir clash
cd ~/clash && curl -sSL -O https://github.com/haishanh/yacd/archive/gh-pages.zip && unzip gh-pages.zip && mv yacd-gh-pages ui
docker run --name Clash -d -v ~/clash/config.yaml:/root/.config/clash/config.yaml -v ~/clash/ui:/root/.config/clash/ui  --restart=unless-stopped --network="host" --privileged dreamacro/clash

自动更新代理配置

# 下载节点配置文件
wget -O config.yaml https://你的clash订阅连接
# 有些供应商会把 external-controller 设为 127.0.0.1,导致很多人搭起来连不上。这里替换成 0.0.0.0
sed -i 's/127.0.0.1:9090/0.0.0.0:9090/g' config.yaml
# 重启 clash 容器
docker container restart clash
# 等待 5 秒,clash 服务启动需要一点时间
sleep 5
# 设置你常用的节点。其中 香港 03* 就是我常用节点的名称
curl -X PUT -H "Content-Type: application/json" -d '{"name": "香港 03*"}' "http://192.168.0.5:9090/proxies/PROXY

version: '3.4'

services:
  clash:
    image: dreamacro/clash-premium:2021.07.03
    cap_add:
      - NET_ADMIN
    devices:
      - /dev/net/tun
    restart: unless-stopped
    volumes:
      - ./config.yaml:/root/.config/clash/config.yaml:ro
    network_mode: host
    # When your system is Linux, you can use `network_mode: "host"` directly.
    container_name: clash

参考

https://zhuanlan.zhihu.com/p/423684520

https://1024.ee/index.php/2021/02/25/mac%E4%B8%8A%E9%80%9A%E8%BF%87docker%E6%9D%A5%E8%BF%90%E8%A1%8Cclash%E5%B9%B6%E5%BC%80%E5%90%AFweb-ui/

标签: none

添加新评论