This image runs a WireGuard VPN client inside a Docker container and acts as a gateway for a Docker network to reach one or more remote subnets behind the VPN.
Features
systemd-resolved / resolvconf dependency)Docker Hub: izetmolla/wireguard-router:latest
GitHub: This repository
/dev/net/tun and CAP_NET_ADMIN in Dockersudo modprobe wireguard
| Variable | Required | Description |
|---|---|---|
DOCKER_NET_CIDR | ✅ | CIDR of the Docker bridge network used by the VPN client (e.g., 10.10.12.0/24). |
REMOTE_LAN_CIDRS | ✅ | Space-separated list of remote LAN subnets reachable via VPN (e.g., "10.20.20.0/24 192.168.50.0/24"). |
WG_INTERFACE | ❌ | WireGuard interface name (default: wg0). |
VPN_DNS | ❌ | Comma-separated DNS servers for the container (default: 1.1.1.1). |
WG_CONFIG_PATH | ❌ | Path to WireGuard config file inside container (default: /etc/wireguard/wg0.conf). |
WG_CONF | ❌* | WireGuard config as plain text (multi-line string). |
WG_CONF_B64 | ❌* | WireGuard config as Base64-encoded string. |
Note: At least one WireGuard config source is required:
- Mount a file to
$WG_CONFIG_PATHOR- Provide
WG_CONFORWG_CONF_B64.
docker run -it --rm --cap-add NET_ADMIN --device /dev/net/tun -e DOCKER_NET_CIDR=10.10.12.0/24 -e REMOTE_LAN_CIDRS="10.20.20.0/24 192.168.50.0/24" -v $(pwd)/wg0.conf:/etc/wireguard/wg0.conf:ro izetmolla/wireguard-router:latest
WG_CONFdocker run -it --rm --cap-add NET_ADMIN --device /dev/net/tun -e DOCKER_NET_CIDR=10.10.12.0/24 -e REMOTE_LAN_CIDRS="10.20.20.0/24" -e WG_CONF="[Interface]\nPrivateKey=...\nAddress=10.8.0.2/24\n\n[Peer]\nPublicKey=...\nEndpoint=example.com:51820\nAllowedIPs=0.0.0.0/0" izetmolla/wireguard-router:latest
WG_CONF_B64export WG_CONF_B64=$(base64 -w0 wg0.conf)
docker run -it --rm --cap-add NET_ADMIN --device /dev/net/tun -e DOCKER_NET_CIDR=10.10.12.0/24 -e REMOTE_LAN_CIDRS="10.20.20.0/24" -e WG_CONF_B64="$WG_CONF_B64" izetmolla/wireguard-router:latest
version: "3.8"
networks:
vpn-net:
driver: bridge
ipam:
config:
- subnet: 10.10.12.0/24
services:
wgclient:
image: izetmolla/wireguard-router:latest
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
volumes:
- ./wg0.conf:/etc/wireguard/wg0.conf:ro
environment:
DOCKER_NET_CIDR: "10.10.12.0/24"
REMOTE_LAN_CIDRS: "10.20.20.0/24 192.168.50.0/24"
VPN_DNS: "1.1.1.1,1.0.0.1"
networks:
vpn-net:
ipv4_address: 172.28.0.254
restart: unless-stopped
app1:
image: alpine:3.20
networks: [vpn-net]
cap_add: [NET_ADMIN]
entrypoint: [
"sh", "-c",
"apk add --no-cache iproute2 && ip route add 10.20.20.0/24 via 172.28.0.254 && sleep infinity"
]
wg-quick.DOCKER_NET_CIDR and each REMOTE_LAN_CIDRS subnet.Missing DOCKER_NET_CIDR → Set the Docker network CIDR in env.No WireGuard config provided → Provide WG_CONF, WG_CONF_B64, or mount a file./dev/net/tun → Run container with --device /dev/net/tun and CAP_NET_ADMIN.MIT License.
See LICENSE file for details.
Pull requests and issues are welcome! Please ensure changes are tested before submission.
Content type
Image
Digest
sha256:4eaa4d432…
Size
36.9 MB
Last updated
about 1 year ago
docker pull izetmolla/wireguard-router