Setup Wireguard VPN server with Docker
Get and setup a server
Both Vultr and DigitalOcean offers as inexpensive as $5 per month servers. So please choose by datacenter location.
You may register with my affiliate links below.
Install Docker
Setup Wireguard
Run these on your server:
mkdir -p ~/wireguard/
mkdir -p ~/wireguard/config/
nano ~/wireguard/docker-compose.yml
Copy and paste the content below:
version: '3.8'
services:
wireguard:
container_name: wireguard
image: linuxserver/wireguard
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Hong_Kong
- SERVERURL=1.2.3.4
- SERVERPORT=51820
- PEERS=pc1,pc2,phone1
- PEERDNS=auto
- INTERNAL_SUBNET=10.0.0.0
ports:
- 51820:51820/udp
volumes:
- type: bind
source: ./config/
target: /config/
- type: bind
source: /lib/modules
target: /lib/modules
restart: always
cap_add:
- NET_ADMIN
- SYS_MODULE
sysctls:
- net.ipv4.conf.all.src_valid_mark=1
There are several places you need to modify.
TZ
refers to timezone. Choose yours fromTZ database name
from Wikipedia.SERVERURL
refers to the server IP address. Find it on Vultr or DigitalOcean dashboard.PEERS
are the number of user-config-files to generate, or the names of user-config-files. If you enterPEERS=3
, it will generatepeer_1
,peer_2
andpeer_3
. If you enterPEERS=pc1,pc2,phone1
, it will generatepeer_pc1
,peer_pc2
andpeer_phone1
.
Hit CTRL
+ X
, Y
, ENTER
to save and exit the file.
Start Wireguard by running these:
cd ~/wireguard/
docker-compose up -d
It starts building the server. After you see Creating wireguard ... done
Connect your phone to Wireguard
docker-compose logs -f wireguard
You will see the execution log, and QR codes of Wireguard VPN connection settings.
Open Wireguard VPN application on your phone, click +
, Create from QR code