使用 docker 快速部署 sing-box TUN透明代理指南

· 3min · sorubedo

本文使用 Docker 快速部署 sing-box TUN 透明代理,适用于常规 Linux/Gnu 发行版。

通过 subsing 将 Clash/Mihomo 订阅注入配置模板。

订阅地址和面板密码统一保存在 .env 中。

需要提前安装 Docker。所有 docker 命令需 root 权限(或 sudo) 将用户加入 docker 组虽可免密但存在安全隐患,不推荐。

[!TIP] 不开 TUN 可跳过 root 要求,但这里的配置模板使用 TUN 透明代理。

目录结构(点击展开)
sing-box/
├── .env                     # 订阅地址、面板密码(不要提交到 Git)
├── .gitignore
├── compose.yml
├── rendered/
│   └── config.json          # envsubst 生成的中间文件
└── workdir/
    ├── config.json.template
    └── config.json          # subsing 生成,供 sing-box 使用

创建文件

创建文件结构(点击展开)
mkdir -p sing-box/{workdir,rendered}
cd sing-box

cat > compose.yml <<'YAML'
services:
  sing-box:
    image: ghcr.io/sagernet/sing-box:latest-testing
    container_name: sing-box
    restart: always
    network_mode: host
    pid: "host"
    cap_add:
      - NET_ADMIN
      - SYS_PTRACE
      - DAC_READ_SEARCH
    devices:
      - /dev/net/tun:/dev/net/tun
    volumes:
      - ./workdir:/workdir
    command: -D /workdir run
YAML

cat > .env <<'ENV'
SUBSCRIPTION_URL=https://example.com/your-subscription
DASHBOARD_SECRET=replace-with-a-strong-password
DASHBOARD_LISTEN=127.0.0.1
ENV

cat > .gitignore <<'EOF'
.env
rendered/
workdir/config.json
EOF

chmod 600 .env
国内镜像版 `compose.yml`(点击展开)

ghcr.1ms.run 代理 ghcr.io 镜像:

cat > compose.yml <<'YAML'
services:
  sing-box:
    image: ghcr.1ms.run/sagernet/sing-box:latest-testing
    container_name: sing-box
    restart: always
    network_mode: host
    pid: "host"
    cap_add:
      - NET_ADMIN
      - SYS_PTRACE
      - DAC_READ_SEARCH
    devices:
      - /dev/net/tun:/dev/net/tun
    volumes:
      - ./workdir:/workdir
    command: -D /workdir run
YAML
编辑 `.env`,把示例值改成自己的订阅链接和面板密码。(点击展开)
nano .env

写入模板

规则集和 Dashboard 通过代理节点下载。如果你的订阅节点质量好,用这个。

模板 1:代理拉规则(点击展开)
cat > workdir/config.json.template <<'JSON'
{
  "log": {
    "level": "error"
  },
  "_providers": [
    {
      "type": "remote",
      "tag": "provider1",
      "url": "${SUBSCRIPTION_URL}",
      "user_agent": "mihomo"
    }
  ],
  "dns": {
    "servers": [
      {
        "type": "fakeip",
        "tag": "FakeDns",
        "inet4_range": "28.0.0.0/8",
        "inet6_range": "fc00::/18"
      },
      {
        "type": "https",
        "tag": "Local-DNS",
        "server": "223.5.5.5"
      },
      {
        "type": "https",
        "tag": "Remote-DNS",
        "detour": "🚀 节点选择",
        "server": "8.8.8.8"
      }
    ],
    "rules": [
      {
        "type": "logical",
        "mode": "and",
        "rules": [
          {
            "domain_suffix": [
              ".lan",
              ".localdomain",
              ".example",
              ".invalid",
              ".localhost",
              ".test",
              ".local",
              ".home.arpa",
              ".msftconnecttest.com",
              ".msftncsi.com",
              ".market.xiaomi.com",
              ".wotgame.cn",
              ".wggames.cn",
              ".wowsgame.cn",
              ".wargaming.net",
              ".steamcontent.com"
            ],
            "invert": true
          },
          {
            "query_type": [
              "A",
              "AAAA"
            ]
          }
        ],
        "server": "FakeDns"
      },
      {
        "rule_set": "CN-Domain",
        "server": "Local-DNS"
      }
    ],
    "final": "Remote-DNS",
    "strategy": "prefer_ipv4"
  },
  "http_clients": [
    {
      "tag": "direct",
      "engine": "go",
      "version": 2,
      "stream_receive_window": 0,
      "connection_receive_window": 0
    },
    {
      "tag": "proxy",
      "engine": "go",
      "version": 2,
      "detour": "🚀 节点选择",
      "stream_receive_window": 0,
      "connection_receive_window": 0
    }
  ],
  "inbounds": [
    {
      "type": "mixed",
      "tag": "mixed-in",
      "listen": "127.0.0.1",
      "listen_port": 1080,
      "tcp_fast_open": true,
      "udp_fragment": true
    },
    {
      "type": "socks",
      "tag": "bittorrent-tracker-in",
      "listen": "0.0.0.0",
      "listen_port": 1081,
      "tcp_fast_open": true,
      "udp_fragment": true,
      "users": [
        {
          "Username": "sorubedo",
          "Password": "obedur"
        }
      ]
    },
    {
      "type": "tun",
      "tag": "tun-in",
      "interface_name": "SB0",
      "mtu": 9000,
      "address": [
        "172.18.0.1/30",
        "fdfe:dcba:9876::1/126"
      ],
      "auto_route": true,
      "auto_redirect": true,
      "strict_route": true,
      "stack": "mixed"
    }
  ],
  "outbounds": [
    {
      "type": "selector",
      "tag": "🚀 节点选择",
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🐼 中国大陆",
      "outbounds": [
        "直连",
        "🚀 节点选择"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🧲 Bittorrent-tracker",
      "outbounds": [
        "直连",
        "🚀 节点选择",
        "🐼 中国大陆"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🧲 Bittorrent-p2p",
      "outbounds": [
        "直连",
        "🚀 节点选择",
        "🐼 中国大陆"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "❤️ AI-!CN",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🐟 漏网之鱼",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "📺 Bilibili",
      "outbounds": [
        "🐼 中国大陆",
        "🚀 节点选择",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🛰 Telegram",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "💻 Github",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🪟 Microsoft",
      "outbounds": [
        "🐼 中国大陆",
        "🚀 节点选择",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🎥 Youtube",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🌈 Google",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🍎 Apple",
      "outbounds": [
        "🐼 中国大陆",
        "🚀 节点选择",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "direct",
      "tag": "直连"
    }
  ],
  "route": {
    "rules": [
      {
        "action": "sniff"
      },
      {
        "protocol": "dns",
        "action": "hijack-dns"
      },
      {
        "ip_is_private": true,
        "outbound": "直连"
      },
      {
        "inbound": "bittorrent-tracker-in",
        "outbound": "🧲 Bittorrent-tracker"
      },
      {
        "protocol": "bittorrent",
        "outbound": "🧲 Bittorrent-p2p"
      },
      {
        "rule_set": "AI-!CN-Domain",
        "outbound": "❤️ AI-!CN"
      },
      {
        "rule_set": "Bilibili-Domain",
        "outbound": "📺 Bilibili"
      },
      {
        "rule_set": "Telegram-Domain",
        "outbound": "🛰 Telegram"
      },
      {
        "rule_set": "Github-Domain",
        "outbound": "💻 Github"
      },
      {
        "rule_set": "Microsoft-Domain",
        "outbound": "🪟 Microsoft"
      },
      {
        "rule_set": "Youtube-Domain",
        "outbound": "🎥 Youtube"
      },
      {
        "rule_set": "Google-Domain",
        "outbound": "🌈 Google"
      },
      {
        "rule_set": "Apple-Domain",
        "outbound": "🍎 Apple"
      },
      {
        "rule_set": "CN-Domain",
        "outbound": "🐼 中国大陆"
      },
      {
        "rule_set": "!CN-Location-Domain",
        "outbound": "🚀 节点选择"
      },
      {
        "action": "resolve"
      },
      {
        "rule_set": "Bilibili-IP",
        "outbound": "📺 Bilibili"
      },
      {
        "rule_set": "Telegram-IP",
        "outbound": "🛰 Telegram"
      },
      {
        "rule_set": "Google-IP",
        "outbound": "🌈 Google"
      },
      {
        "rule_set": "Apple-IP",
        "outbound": "🍎 Apple"
      },
      {
        "rule_set": "CN-IP",
        "outbound": "🐼 中国大陆"
      }
    ],
    "rule_set": [
      {
        "type": "remote",
        "tag": "AI-!CN-Domain",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/category-ai-!cn.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Github-Domain",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/github.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Microsoft-Domain",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/microsoft.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Youtube-Domain",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/youtube.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Google-Domain",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/google.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Google-IP",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geoip/google.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Bilibili-Domain",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/bilibili.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Bilibili-IP",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo-lite/geoip/bilibili.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Telegram-Domain",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/telegram.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Telegram-IP",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geoip/telegram.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "CN-Domain",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/cn.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "CN-IP",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geoip/cn.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "!CN-Location-Domain",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/geolocation-!cn.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Apple-Domain",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/apple.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Apple-IP",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo-lite/geoip/apple.srs",
        "update_interval": "2h0m0s"
      }
    ],
    "final": "🐟 漏网之鱼",
    "find_process": true,
    "auto_detect_interface": true,
    "default_domain_resolver": {
      "server": "Local-DNS",
      "strategy": "prefer_ipv4"
    },
    "default_http_client": "proxy"
  },
  "services": [
    {
      "type": "api",
      "listen": "${DASHBOARD_LISTEN}",
      "listen_port": 23333,
      "secret": "${DASHBOARD_SECRET}",
      "access_control_allow_private_network": true,
      "dashboard": {
        "enabled": true,
        "download_url": "https://github.com/Zephyruso/zashboard/releases/latest/download/dist.zip",
        "http_client": "proxy"
      }
    }
  ],
  "experimental": {
    "cache_file": {
      "enabled": true,
      "path": "cache.db",
      "store_fakeip": true,
      "rdrc_timeout": "168h0m0s",
      "store_dns": true
    }
  }
}
JSON

节点质量差、GitHub 拉不动规则集时用这个。所有规则 URL 走 ghfast.top 镜像 + 直连下载。

模板 2:直连拉规则(点击展开)
cat > workdir/config.json.template <<'JSON'
{
  "log": {
    "level": "error"
  },
  "_providers": [
    {
      "type": "remote",
      "tag": "provider1",
      "url": "${SUBSCRIPTION_URL}",
      "user_agent": "mihomo"
    }
  ],
  "dns": {
    "servers": [
      {
        "type": "fakeip",
        "tag": "FakeDns",
        "inet4_range": "28.0.0.0/8",
        "inet6_range": "fc00::/18"
      },
      {
        "type": "https",
        "tag": "Local-DNS",
        "server": "223.5.5.5"
      },
      {
        "type": "https",
        "tag": "Remote-DNS",
        "detour": "🚀 节点选择",
        "server": "8.8.8.8"
      }
    ],
    "rules": [
      {
        "type": "logical",
        "mode": "and",
        "rules": [
          {
            "domain_suffix": [
              ".lan",
              ".localdomain",
              ".example",
              ".invalid",
              ".localhost",
              ".test",
              ".local",
              ".home.arpa",
              ".msftconnecttest.com",
              ".msftncsi.com",
              ".market.xiaomi.com",
              ".wotgame.cn",
              ".wggames.cn",
              ".wowsgame.cn",
              ".wargaming.net",
              ".steamcontent.com"
            ],
            "invert": true
          },
          {
            "query_type": [
              "A",
              "AAAA"
            ]
          }
        ],
        "server": "FakeDns"
      },
      {
        "rule_set": "CN-Domain",
        "server": "Local-DNS"
      }
    ],
    "final": "Remote-DNS",
    "strategy": "prefer_ipv4"
  },
  "http_clients": [
    {
      "tag": "direct",
      "engine": "go",
      "version": 2,
      "stream_receive_window": 0,
      "connection_receive_window": 0
    },
    {
      "tag": "proxy",
      "engine": "go",
      "version": 2,
      "detour": "🚀 节点选择",
      "stream_receive_window": 0,
      "connection_receive_window": 0
    }
  ],
  "inbounds": [
    {
      "type": "mixed",
      "tag": "mixed-in",
      "listen": "127.0.0.1",
      "listen_port": 1080,
      "tcp_fast_open": true,
      "udp_fragment": true
    },
    {
      "type": "socks",
      "tag": "bittorrent-tracker-in",
      "listen": "0.0.0.0",
      "listen_port": 1081,
      "tcp_fast_open": true,
      "udp_fragment": true,
      "users": [
        {
          "Username": "sorubedo",
          "Password": "obedur"
        }
      ]
    },
    {
      "type": "tun",
      "tag": "tun-in",
      "interface_name": "SB0",
      "mtu": 9000,
      "address": [
        "172.18.0.1/30",
        "fdfe:dcba:9876::1/126"
      ],
      "auto_route": true,
      "auto_redirect": true,
      "strict_route": true,
      "stack": "mixed"
    }
  ],
  "outbounds": [
    {
      "type": "selector",
      "tag": "🚀 节点选择",
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🐼 中国大陆",
      "outbounds": [
        "直连",
        "🚀 节点选择"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🧲 Bittorrent-tracker",
      "outbounds": [
        "直连",
        "🚀 节点选择",
        "🐼 中国大陆"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🧲 Bittorrent-p2p",
      "outbounds": [
        "直连",
        "🚀 节点选择",
        "🐼 中国大陆"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "❤️ AI-!CN",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🐟 漏网之鱼",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "📺 Bilibili",
      "outbounds": [
        "🐼 中国大陆",
        "🚀 节点选择",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🛰 Telegram",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "💻 Github",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🪟 Microsoft",
      "outbounds": [
        "🐼 中国大陆",
        "🚀 节点选择",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🎥 Youtube",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🌈 Google",
      "outbounds": [
        "🚀 节点选择",
        "🐼 中国大陆",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "selector",
      "tag": "🍎 Apple",
      "outbounds": [
        "🐼 中国大陆",
        "🚀 节点选择",
        "直连"
      ],
      "_use_all_providers": true,
      "interrupt_exist_connections": true
    },
    {
      "type": "direct",
      "tag": "直连"
    }
  ],
  "route": {
    "rules": [
      {
        "action": "sniff"
      },
      {
        "protocol": "dns",
        "action": "hijack-dns"
      },
      {
        "ip_is_private": true,
        "outbound": "直连"
      },
      {
        "inbound": "bittorrent-tracker-in",
        "outbound": "🧲 Bittorrent-tracker"
      },
      {
        "protocol": "bittorrent",
        "outbound": "🧲 Bittorrent-p2p"
      },
      {
        "rule_set": "AI-!CN-Domain",
        "outbound": "❤️ AI-!CN"
      },
      {
        "rule_set": "Bilibili-Domain",
        "outbound": "📺 Bilibili"
      },
      {
        "rule_set": "Telegram-Domain",
        "outbound": "🛰 Telegram"
      },
      {
        "rule_set": "Github-Domain",
        "outbound": "💻 Github"
      },
      {
        "rule_set": "Microsoft-Domain",
        "outbound": "🪟 Microsoft"
      },
      {
        "rule_set": "Youtube-Domain",
        "outbound": "🎥 Youtube"
      },
      {
        "rule_set": "Google-Domain",
        "outbound": "🌈 Google"
      },
      {
        "rule_set": "Apple-Domain",
        "outbound": "🍎 Apple"
      },
      {
        "rule_set": "CN-Domain",
        "outbound": "🐼 中国大陆"
      },
      {
        "rule_set": "!CN-Location-Domain",
        "outbound": "🚀 节点选择"
      },
      {
        "action": "resolve"
      },
      {
        "rule_set": "Bilibili-IP",
        "outbound": "📺 Bilibili"
      },
      {
        "rule_set": "Telegram-IP",
        "outbound": "🛰 Telegram"
      },
      {
        "rule_set": "Google-IP",
        "outbound": "🌈 Google"
      },
      {
        "rule_set": "Apple-IP",
        "outbound": "🍎 Apple"
      },
      {
        "rule_set": "CN-IP",
        "outbound": "🐼 中国大陆"
      }
    ],
    "rule_set": [
      {
        "type": "remote",
        "tag": "AI-!CN-Domain",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/category-ai-!cn.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Github-Domain",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/github.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Microsoft-Domain",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/microsoft.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Youtube-Domain",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/youtube.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Google-Domain",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/google.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Google-IP",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geoip/google.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Bilibili-Domain",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/bilibili.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Bilibili-IP",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo-lite/geoip/bilibili.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Telegram-Domain",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/telegram.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Telegram-IP",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geoip/telegram.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "CN-Domain",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/cn.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "CN-IP",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geoip/cn.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "!CN-Location-Domain",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/geolocation-!cn.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Apple-Domain",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/apple.srs",
        "update_interval": "2h0m0s"
      },
      {
        "type": "remote",
        "tag": "Apple-IP",
        "url": "https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo-lite/geoip/apple.srs",
        "update_interval": "2h0m0s"
      }
    ],
    "final": "🐟 漏网之鱼",
    "find_process": true,
    "auto_detect_interface": true,
    "default_domain_resolver": {
      "server": "Local-DNS",
      "strategy": "prefer_ipv4"
    },
    "default_http_client": "direct"
  },
  "services": [
    {
      "type": "api",
      "listen": "${DASHBOARD_LISTEN}",
      "listen_port": 23333,
      "secret": "${DASHBOARD_SECRET}",
      "access_control_allow_private_network": true,
      "dashboard": {
        "enabled": true,
        "download_url": "https://ghfast.top/https://github.com/Zephyruso/zashboard/releases/latest/download/dist.zip",
        "http_client": "direct"
      }
    }
  ],
  "experimental": {
    "cache_file": {
      "enabled": true,
      "path": "cache.db",
      "store_fakeip": true,
      "rdrc_timeout": "168h0m0s",
      "store_dns": true
    }
  }
}
JSON

生成配置

envsubst 渲染变量(点击展开)
docker run --rm \
  --env-file .env \
  -v "$PWD/workdir/config.json.template:/workdir/config.json:ro" \
  -v "$PWD/rendered:/processed" \
  dibi/envsubst:latest
envsubst 渲染变量 · 国内镜像 docker.1ms.run(点击展开)
docker run --rm \
  --env-file .env \
  -v "$PWD/workdir/config.json.template:/workdir/config.json:ro" \
  -v "$PWD/rendered:/processed" \
  docker.1ms.run/dibi/envsubst:latest
subsing 注入节点生成配置(点击展开)
docker run --rm \
  -v "$PWD/rendered/config.json:/workdir/config.json:ro" \
  -v "$PWD/workdir:/processed" \
  ghcr.io/sorubedo/subsing:latest
subsing 注入节点 · 国内镜像 ghcr.1ms.run(点击展开)
docker run --rm \
  -v "$PWD/rendered/config.json:/workdir/config.json:ro" \
  -v "$PWD/workdir:/processed" \
  ghcr.1ms.run/sorubedo/subsing:latest

执行后会生成 workdir/config.json。每次修改 .env 或切换模板,都需要依次重新运行上面两个命令。

启动前可以先检查配置:

检查配置(点击展开)
docker compose run --rm sing-box check -c /workdir/config.json

启动和维护

启用服务(点击展开)
docker compose up
后台启用服务(点击展开)
docker compose up -d
禁用服务(点击展开)
docker compose down
重启服务(点击展开)
docker compose restart
更新 sing-box(点击展开)
docker compose pull # 拉取新镜像
docker compose down # 禁用旧服务
docker compose up -d # 启用新服务
查看日志(点击展开)
docker compose logs

面板

浏览器打开 http://127.0.0.1:23333,选择 sing-box api,主机127.0.0.1 端口23333