Set Up a Secure WireGuard VPN with Docker & Docker Compose | Step-by-Step Tutorial

Опубликовано: 28 Апрель 2026
на канале: Monovm
890
9

In this tutorial, you’ll learn how to quickly and securely deploy a WireGuard VPN server using Docker and Docker Compose on Ubuntu.

Perfect for personal use or managing remote teams. Complete with a clean web UI and advanced options, such as iptables routing.

Covers Docker installation, service configuration, UI access, and optional NAT setup.

Suitable for both beginners and advanced users.

Don’t forget to like, comment, and subscribe for more server and networking guides!

Commands:
—-
Part 1
Step 1

ca-certificates
curl

sudo apt-get update

sudo apt-get install ca-certificates curl

sudo install -m 0755 -d /etc/apt/keyrings

sudo curl -fsSL https://download.docker.com/linux/ubu... -o /etc/apt/keyrings/docker.asc

sudo chmod a+r /etc/apt/keyrings/docker.asc

sudo apt-get update

services:
wireguard:
image: linuxserver/wireguard:v1.0.20210914-ls7
container_name: wireguard
cap_add:
NET_ADMIN
volumes:
./config:/config
ports:
"5000:5000"
"51820:51820/udp"
restart: unless-stopped

wireguard-ui:
image: ngoduykhanh/wireguard-ui: latest
container_name: wireguard-ui
depends_on:
wireguard
cap_add:
NET_ADMIN
Use the network of the 'WireGuard' service. This enables showing active clients in the status page
network_mode: service:wireguard
environment:
SENDGRID_API_KEY
EMAIL_FROM_ADDRESS
EMAIL_FROM_NAME
SESSION_SECRET
WGUI_USERNAME=admin
WGUI_PASSWORD=admin
WG_CONF_TEMPLATE
WGUI_MANAGE_START=true
WGUI_MANAGE_RESTART=true
logging:
driver: json-file
options:
max-size: 50m
volumes:
./db:/app/db
./config:/etc/wireguard
restart: unless-stopped

-
Step 2

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

sudo Docker run hello-world

sudo apt-get install docker-compose-plugin

docker compose version

------
Part 2
Step 1

sudo apt update && sudo apt upgrade

sudo mkdir /opt/wg-ui

sudo vi /opt/wg-ui/docker-compose.yml

-
Step 2
wireguard:
image: linuxserver/wireguard

wireguard-ui:
image: ngoduykhanh/wireguard-ui

-
Step 3
sudo Docker compose -f /opt/wg-ui/docker-compose.yml up –d

-----

Part 3
http://your-server-ip:5000

------

Part 4
iptables -A FORWARD -i %1 -j ACCEPT
iptables -A FORWARD -o wg0 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth+ -j MASQUERADE

iptables -D FORWARD -i %1 -j ACCEPT
iptables -D FORWARD -o wg0 -j ACCEPT
iptables -t nat -D POSTROUTING -o eth+ -j MASQUERADE