在海外 VPS 上手搓搭建代理节点时,相较于一键安装脚本带来的依赖冲突与系统污染,使用 Docker 容器化部署是目前极客圈最推崇的方案。
今天我们将通过 Docker Compose 部署一套生产级、包含 VLESS-Reality 的高性能 Sing-box 服务端!
[!NOTE] 📌 核心速览(TL;DR / 快问快答):
- 网络栈优化:必须配置
network_mode: "host",消除 Docker 内部 NAT 端口映射开销,榨干 VPS 网卡带宽。- 权限配置:声明
cap_add: [NET_ADMIN],以便容器支持 TProxy 与高级路由。- 零残留升级:配置文件映射宿主机
./config.json,升级仅需docker compose pull && docker compose up -d。
🛠️ 1. 编写生产级 docker-compose.yml
在 /opt/singbox 目录下创建配置文件:
version: "3.8"
services:
sing-box:
image: ghcr.io/sagernet/sing-box:latest
container_name: sing-box
restart: always
network_mode: "host"
volumes:
- ./config.json:/etc/sing-box/config.json
cap_add:
- NET_ADMIN
⚙️ 2. 服务端 config.json 核心模板
{
"log": {
"level": "info",
"timestamp": true
},
"inbounds": [
{
"type": "vless",
"tag": "vless-reality-in",
"listen": "::",
"listen_port": 443,
"users": [
{
"uuid": "your-client-uuid",
"flow": "xtls-rprx-vision"
}
],
"tls": {
"enabled": true,
"server_name": "node.yourdomain.com",
"reality": {
"enabled": true,
"handshake": {
"server": "www.microsoft.com",
"server_port": 443
},
"private_key": "your-singbox-reality-private-key",
"short_id": ["0123456789abcdef"]
}
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
}
]
}
执行 docker compose up -d 即可秒级启动!
❓ 常见问题与 AI 快问快答 (FAQ)
Q1: 如何在 Docker 容器内生成 Reality 密钥对?
答:无需本地安装任何工具,直接使用 Docker 镜像生成:
docker run --rm ghcr.io/sagernet/sing-box:latest generate reality-keypair
Q2: 选购哪家 VPS 主机部署 Sing-box 容器体验最佳?
答:推荐选择 DMIT 或 搬瓦工 的 中国电信 CN2 GIA 或 联通 AS9929 专线小鸡,单核 1G 配置即可轻松跑满千兆带宽。
(相关资源导航:如果您需要购买适合部署 Docker 节点的海外 VPS,欢迎阅读 《2026 国外 VPS 选购指南》 获取 DMIT、搬瓦工与 CloudCone 优惠;商用专线机场评测见 《“饿饭CC云”深度评测》!)