在 Docker 中运行(社区方案)
在基于官方发布版本构建的 Docker 容器中运行 wantasticd:构建一个小镜像,用 genkey 认领一次,然后以后台方式运行。这不是官方镜像。
你自行构建的容器运行 wantasticd,将认领信息保存在命名卷中,自动重启,并在控制台中显示为 Online。
开始之前
- 带有 TUN 驱动的 Linux 主机上的 Docker Engine 20.10+(或 Podman)。
- 有权限使用 --cap-add NET_ADMIN 和 --device /dev/net/tun 运行容器。
- 一部手机或一个浏览器,用于登录 Wantastic 控制台。
快速安装(5 分钟)
没有官方镜像。你需要基于官方发布版本构建一个小镜像,认领一次,然后在后台运行。无需令牌。
- 1将下方的 Dockerfile 保存到一个空目录中。将 WANTASTIC_ARCH 设置为主机的 CPU 类型(amd64、arm64 或 arm)。
- 2构建镜像,并用认领命令运行一次 genkey。它会打印 Claim URL 和二维码。
- 3扫描二维码或打开 Claim URL,登录后点击 Claim Device。
- 4打印出 "Device claimed" 后,按 Ctrl+C。认领信息已保存在 wantastic 卷中。
- 5使用运行命令在后台启动容器。
FROM alpine:3.20
ARG WANTASTIC_ARCH=amd64
RUN apk add --no-cache ca-certificates curl \
&& TAG=$(curl -fsSL https://get.wantastic.app/latest | cut -d+ -f1) \
&& mkdir -p /tmp/w \
&& curl -fsSL https://get.wantastic.app/$TAG/wantasticd-linux-$WANTASTIC_ARCH.tar.gz | tar -xz -C /tmp/w \
&& install -m 755 "$(find /tmp/w -name wantasticd -type f | head -n 1)" /usr/local/bin/wantasticd \
&& rm -rf /tmp/w \
&& wantasticd version
ENV WANTASTIC_CONFIG_DIR=/etc/wantastic \
WANTASTIC_DNS_MODE=off
VOLUME /etc/wantastic
ENTRYPOINT ["wantasticd"]
CMD ["connect", "--config", "/etc/wantastic/config.conf", "--no-auto-update"]docker build -t wantasticd-local --build-arg WANTASTIC_ARCH=amd64 .
docker run -it --rm --hostname office-docker --cap-add NET_ADMIN --device /dev/net/tun -v wantastic:/etc/wantastic wantasticd-local genkeydocker run -d --name wantasticd --hostname office-docker --restart unless-stopped --cap-add NET_ADMIN --device /dev/net/tun -v wantastic:/etc/wantastic wantasticd-local$ docker run -it --rm --hostname office-docker --cap-add NET_ADMIN --device /dev/net/tun -v wantastic:/etc/wantastic wantasticd-local genkey……Generated device claim key: /etc/wantastic/device-claim-key.jsonPublic key: Vd3hK1oQ7mR2sT9uW4xY6zA8bC0dE2fG4hJ6kL8mN0P=Server URL: https://console.wantastic.appClaim URL: https://console.wantastic.app/#desktop?claim_public_key=Vd3hK1oQ…%3D&wantastic_server=https%3A%2F%2Fconsole.wantastic.app1█▀▀▀▀▀█ ▄▀▄ ▀█▄ █▀▀▀▀▀██ ███ █ ▀█▄▀▄█ █ ███ ██ ▀▀▀ █ ▄▀█ ▀▄ █ ▀▀▀ █▀▀▀▀▀▀▀ ▀ ▀ █ ▀ ▀▀▀▀▀▀▀▀█▄▀▄▀▀█▀▄█▀▄▀▀▄█▀▄▀█▄█▀▀▀▀▀█ █▄▀▄▀█ ▀▄█ ▄▀▀▀▀▀▀▀▀ ▀▀ ▀▀▀ ▀▀▀ ▀▀▀2026/10/29 09:14:03 Waiting for claim. Press Ctrl+C to stop.2026/10/29 09:15:12 Device claimed. Configuration saved to /etc/wantastic/config.conf2^C$ docker run -d --name wantasticd --hostname office-docker --restart unless-stopped --cap-add NET_ADMIN --device /dev/net/tun -v wantastic:/etc/wantastic wantasticd-local3
- 1打开此链接,或扫描二维码
- 2已认领:现在按 Ctrl+C
- 3重启一次服务
- 1Claim public key 已自动填写
- 2Wantastic server 保持默认即可
- 3点击 Claim Device
注意: WANTASTIC_DNS_MODE=off 可防止代理修改由 Docker 管理的容器 DNS。容器中的自动更新处于关闭状态:如需更新,请重新构建镜像。
检查是否正常工作
- 1运行状态命令。它会显示 Status: Connected。
- 2在控制台中打开 Devices。设备显示为 Online。
docker exec wantasticd wantasticd status
docker logs --tail 20 wantasticd$ docker exec wantasticd wantasticd statusStatus: Connected1Version: v1.0.54+377f3c0Mode: TUN (wantastic0)VPN IPs: 10.200.0.14/322Public key: q7ZkV3m1yH0dTn8pXo2bLwR4sE6uJ9cA1fG5hK8iN0M=Server: wg.wantastic.app:51820Exit node: falseLocal access: falseAuto update: trueTraffic: ↓ 18.4 KiB ↑ 9.2 KiBPeers: 2 (direct 1, relay 1)Uptime: 4m12s
- 1隧道已建立
- 2你的覆盖网络地址
- 1按名称搜索
- 2状态显示 Online
- 3覆盖网络 IP 与 wantasticd status 一致
- 4Last seen 持续更新
Docker Compose
- 默认网络:只有容器位于覆盖网络中。
- network_mode: host 会将 wantastic0 放到主机上,这样主机本身也可以通过覆盖网络访问。
services:
wantasticd:
build:
context: .
args:
WANTASTIC_ARCH: amd64
image: wantasticd-local
hostname: office-docker
restart: unless-stopped
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
volumes:
- wantastic:/etc/wantastic
# network_mode: host # put wantastic0 on the host itself
volumes:
wantastic: {}docker compose run --rm wantasticd genkey
# after "Device claimed": press Ctrl+C, then:
docker compose up -d更新
docker build --no-cache -t wantasticd-local --build-arg WANTASTIC_ARCH=amd64 .
docker rm -f wantasticd
# then run the "Run in the background" command again (the volume keeps the claim)其他安装方式
仅在自动化或特殊情况下才需要这些方式。上面的快速安装是最简单的方法。
使用 Account → Secrets 中的令牌向卷中登录一次,然后使用运行命令。
docker run --rm --hostname office-docker -v wantastic:/etc/wantastic wantasticd-local login --no-connect --token <TOKEN>像对待密码一样对待令牌。在其过期之前,任何持有它的人都能向你的账户添加设备。
- 1打开 Secrets 选项卡
- 2点击 + New Secret
- 3为其命名
- 4点击 Generate
- 5复制新密钥
验证结果
常见问题
容器因 TUN 错误立即停止。Failed to start agent: create device: create tun: CreateTUN("wantastic0") failed; /dev/net/tun does not existdocker logs
启动容器时没有使用 --device /dev/net/tun,或主机没有 TUN 驱动。
在主机上加载 TUN,然后使用快速安装中的确切运行命令。
sudo modprobe tun容器因权限错误而停止。operation not permitteddocker logs
缺少 NET_ADMIN 能力,或运行时为 rootless 模式。
添加 --cap-add NET_ADMIN。使用 rootless Docker 或 Podman 时,请以 root 身份运行容器。
容器启动后立即循环重启。Config not found at /etc/wantastic/config.conf. Run `wantasticd genkey --out <key>` to create a claim key and wait for claim, or pass --wait-claim with an existing key.docker logs
容器从未被认领,或使用了不同的卷。
使用相同的卷名运行一次认领命令,然后再次启动容器。
docker run -it --rm --hostname office-docker --cap-add NET_ADMIN --device /dev/net/tun -v wantastic:/etc/wantastic wantasticd-local genkey
docker restart wantasticd在容器内运行 install.sh 时在最后失败。System has not been booted with systemd as init system (PID 1). Can't operate.install.sh
容器通常没有 systemd。
请使用本页的 Dockerfile,而不是安装程序。
日志每小时都显示更新失败。Error: no supported service manager found; refusing an unverifiable updatedocker logs
自动更新已开启,但容器没有服务管理器。
在 CMD 中保留 --no-auto-update(与 Dockerfile 中相同),并通过重新构建镜像来更新。
认领或登录被拒绝。Login failed: account has reached its device limit — upgrade your plan or remove an existing devicewantasticd login / 控制台
你的套餐设备数量已满。控制台显示 "You have reached the maximum number of devices for your plan."
在 Devices 中删除一台不再使用的设备(设备行 → Delete),或升级套餐。然后重新认领。
status 显示 Running (tunnel down),或 peers 显示 (server) 为 HANDSHAKE never。Device health check failed: …服务日志
网络阻止了到中心节点(wg.wantastic.app)的出站 UDP 51820 端口,或 DNS 不可用。
在防火墙中放行出站 UDP 51820,然后重启服务。
nslookup wg.wantastic.app
docker restart wantasticd继续阅读
仍然无法解决?
请通过邮件发送设备名称、平台和完整的错误文本。切勿发送令牌、密钥或密码。