How to Run a WireGuard Tunnel Inside a Docker Container Without Kernel Support

How to Run a WireGuard Tunnel Inside a Docker Container Without Kernel Support
If your NAS or Linux host does not support the WireGuard kernel module โ like the Synology DS220+ โ you can still run a secure WireGuard tunnel using Docker and wireguard-go
. This article walks you through the full setup with downloadable examples and scripts.
๐ซ Why This Setup?
Many embedded Linux systems (e.g., Synology NAS, LXC, OpenVZ VPS) lack support for kernel modules like wireguard.ko
. Fortunately, the Go-based wireguard-go
project allows running WireGuard entirely in user space. When combined with Docker, it enables a portable and rootless VPN tunnel.
๐ง What You’ll Achieve
- A working WireGuard VPN tunnel inside a Docker container
- Fully functional without kernel support
- Persistent setup for backup, replication, or remote access
- Ready-to-use configuration and generation scripts
๐ Requirements
- Synology DS220+ (or similar Linux NAS)
- Docker and SSH/root access
x86_64
architecture (for the provided binary)
๐ Folder Structure
|
|
๐ Quick Setup
Before starting the tunnel, follow these steps to prepare the environment.
โ 1. Download Files
Use the install script to download all necessary files:
|
|
๐ 2. Generate WireGuard Keys
Run the key generation script:
|
|
This will:
- Generate a
PrivateKey
andPublicKey
using a temporary container - Save a template
wg0.conf
file in the current directory
โ๏ธ 3. Edit wg0.conf
Open the generated file and update the following:
PublicKey
of your WireGuard serverEndpoint
โ IP or domain of the server (e.g.vpn.example.com:51820
)- Optional: update
Address
orAllowedIPs
to match your network
๐ 4. Ensure Network Access
Make sure:
- UDP port
51820
(or the one used) is open on your server - The system supports
--privileged
Docker containers - Host network mode is available (
network_mode: host
)
โถ๏ธ 5. Start the Tunnel
Now you can build and run the container:
|
|
To check if the tunnel is working:
|
|
๐ Example wg0.conf
|
|
๐ Launch Container Manually
If not using docker-compose
, run manually:
|
|
Use --privileged
and --network host
to allow full tunnel capabilities.
๐งพ View Logs and Debug
To view logs from the running container:
|
|
To enter the container’s shell (for inspection or testing):
|
|
From inside the container, you can also run:
|
|
to check tunnel status directly.
โป๏ธ Clean Shutdown & Restart
|
|
๐ก Watchdog via Cron (optional)
Monitor tunnel health and auto-restart if down:
|
|
Add:
|
|
๐ง Manually Compile wireguard-go (if needed)
|
|
๐ Useful Links
- ๐ WireGuard Documentation
- ๐ GitHub Source Files
- ๐ Install Script
- ๐ Full README
๏ธโฃ Need help with customization or scaling? Reach out via blog.topli.ch or GitHub.
ยฉ 2025 run.topli.ch