设置 docker 非特权模式

This commit is contained in:
bjdgyc 2025-02-27 16:31:17 +08:00
parent a77f4cae84
commit 8329e8ec4f
3 changed files with 17 additions and 9 deletions

View File

@ -439,7 +439,18 @@ ipv4_end = "10.1.2.200"
--ip_lease=1209600 # IP地址租约时长 --ip_lease=1209600 # IP地址租约时长
``` ```
7. 构建镜像 (非必需) 9. 使用非特权模式启动容器
```bash
# 参数可以参考 ./anylink tool -d
# 可以使用命令行参数 或者 环境变量 配置
docker run -itd --name anylink \
-p 443:443 -p 8800:8800 -p 443:443/udp \
-v /dev/net/tun:/dev/net/tun --cap-add=NET_ADMIN \
--restart=always \
bjdgyc/anylink
```
10. 构建镜像 (非必需)
```bash ```bash
#获取仓库源码 #获取仓库源码
git clone https://github.com/bjdgyc/anylink.git git clone https://github.com/bjdgyc/anylink.git

View File

@ -31,10 +31,10 @@ func checkTun() {
base.Fatal("testTun err: ", err) base.Fatal("testTun err: ", err)
} }
// 开启服务器转发 // 开启服务器转发
err = execCmd([]string{"sysctl -w net.ipv4.ip_forward=1"}) // err = execCmd([]string{"sysctl -w net.ipv4.ip_forward=1"})
if err != nil { // if err != nil {
base.Fatal(err) // base.Fatal(err)
} // }
if base.Cfg.IptablesNat { if base.Cfg.IptablesNat {
// 添加NAT转发规则 // 添加NAT转发规则
ipt, err := iptables.New() ipt, err := iptables.New()

View File

@ -20,10 +20,7 @@ func Start() {
admin.InitLockManager() //初始化防爆破定时器和IP白名单 admin.InitLockManager() //初始化防爆破定时器和IP白名单
// 开启服务器转发 // 开启服务器转发
err := execCmd([]string{"sysctl -w net.ipv4.ip_forward=1"}) execCmd([]string{"sysctl -w net.ipv4.ip_forward=1"})
if err != nil {
base.Fatal(err)
}
switch base.Cfg.LinkMode { switch base.Cfg.LinkMode {
case base.LinkModeTUN: case base.LinkModeTUN: