1. 编写 docker-compose.yml
yml
services:
wireguard:
image: linuxserver/wireguard:latest
container_name: wireguard
cap_add:
- NET_ADMIN
- SYS_MODULE
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
- SERVERPORT=51820 # WireGuard 默认端口
- PEERS=1 # 初始生成的客户端配置数量
- PEERDNS=8.8.8.8 # DNS 服务器
- ALLOWEDIPS=0.0.0.0/0 # 允许客户端所有流量走服务端
volumes:
- ./volumes/config:/config # 挂载 WireGuard 容器的主配置目录
- ./volumes/wg:/etc/wireguard # 挂载 WireGuard 核心配置目录
- /lib/modules:/lib/modules
ports:
- 51820:51820/udp
sysctls:
- net.ipv4.conf.all.src_valid_mark=1
- net.ipv4.ip_forward=1
restart: unless-stopped
2. 启动容器
bash
docker-compose up -d
3. 获取客户端配置
bash
cat ./volumes/peer1/peer1.conf