# WireGuard Container by RoboData.io A production-ready, zero secrets exposure, secure VPN server.
1.3K
A production-ready, secure WireGuard VPN server in a Docker container.
docker run -d \
--name wireguard \
--cap-add=NET_ADMIN \
--cap-add=NET_RAW \
-p 51820:51820/udp \
-e WG_PEERS='<peer-public-key>:10.0.0.2/32' \
robotributor/wg-robo-server:latest
10.0.0.1/24) - VPN server internal VPN network address and subnet51820) - WireGuard listen porteth0) - Network interface for masqueradingnone) - Networks to masquerade towards. Can have multiple values, coma separatedtrue) - Enable IPv4 forwardingfalse) - Enable NAT masqueradingWG_PEERS='<public-key>:<allowed-ips>,<public-key>:<allowed-ips>'
Example:
WG_PEERS='OMeTfzxZ2a8m4vii2XwqkW5zjbds1mwznF45sKFP8Xk=:10.0.0.2/32'
For more control, use JSON format with optional fields:
WG_PEERS='[
{
"public_key": "OMeTfzxZ2a8m4vii2XwqkW5zjbds1mwznF45sKFP8Xk=",
"allowed_ips": "10.0.0.2/32",
"persistent_keepalive": 25,
"endpoint": "203.0.113.10:51820",
"preshared_key": "base64-encoded-preshared-key=="
}
]'
Format: external_port:internal_ip:internal_port:protocol
Example:
WG_PORT_FORWARDS='8080:10.0.0.4:80:tcp,8090:10.0.0.4:9000:tcp'
This forwards:
version: '3.8'
services:
wireguard:
image: robotributor/wg-robo-server:latest
container_name: wireguard-vpn
cap_add:
- NET_ADMIN
- NET_RAW
ports:
- "51820:51820/udp"
environment:
- WG_ADDRESS=10.100.0.1/24
- WG_PORT=51820
- WG_PEERS=6wM0acu/ctggIuQwkvbC4W89/vRfogG+kuwyIigm+Rc=:10.100.0.2/32
- WG_ENABLE_MASQUERADE=true
- LOG_LEVEL=INFO
volumes:
- wireguard-config:/etc/wireguard
restart: unless-stopped
volumes:
wireguard-config:
This container requires specific Linux capabilities to function:
Example with docker run:
docker run --cap-add=NET_ADMIN --cap-add=NET_RAW ...
The WireGuard keys and configuration are stored in /etc/wireguard. For best security regenerate server private keys in every run and extract them again. If you really need to persist these across container restarts, mount a volume:
docker run -v wireguard-config:/etc/wireguard ...
This ensures:
PRIVATE_KEY=$(wg genkey)
PUBLIC_KEY=$(echo "$PRIVATE_KEY" | wg pubkey)
echo "Private key: $PRIVATE_KEY"
echo "Public key: $PUBLIC_KEY"
unset PRIVATE_KEY
unset PUBLIC_KEY
Store both keys in your password manager and make sure the private key is never shared with anyone. Output will look something like this:
Private key: yI6oZMyUwxcAAPFFYZ5C4J7oPHXkKkBGeyoZaUq+pkM=
Public key: ORvc2GJvq1mSOPXSIhg8tWhQ1Lr6t2XJwtIrqfWDGEE=`
Each key starts with a character and ends up with '=' including.
In case you are using Network Manager in linux, it is preferable to do your Wireguard setup within it. If you prefer to manage your own local wg.conf files, it is better to disable Network Manager
=========================================================================
Server_public_key: NhScYc6sRvo7rjLTsBYRDA3p4V3EaVFjN2kfeVaRan0=
=========================================================================
Now you can connect to your Wireguard VPN.
docker exec wireguard wg show
docker logs -f wireguard
The public key is logged on startup and also saved to /etc/wireguard/publickey:
docker exec wireguard cat /etc/wireguard/publickey
docker exec wireguard wg show wg0 peers
Container won't start: Check that you've added NET_ADMIN and NET_RAW capabilities.
Peers can't connect: Verify peer public keys are correct and WG_PEERS is properly formatted.
Port forwarding doesn't work: Ensure the internal service is reachable at the specified IP address.
No internet for VPN clients: Enable masquerading with WG_ENABLE_MASQUERADE=true and verify IP forwarding is enabled.
git clone <repository-url>
cd wireguard-docker
docker build -t my-wg-robo-server:latest .
Contributions are welcome. Please ensure:
Built and maintained by RoboData.io. For issues, feature requests, or questions, please open an issue on the project repository.
Content type
Image
Digest
sha256:c30b54350…
Size
33.1 MB
Last updated
10 months ago
docker pull robotributor/wg-robo-server