composebuilder

Docker Compose: wg-easy WireGuard VPN with Web UI

Run wg-easy in Docker Compose to host a WireGuard VPN with a web UI for peers. Covers NET_ADMIN, IP forwarding and a localhost-only admin panel.

When to use this stack

WireGuard is a modern VPN protocol with a small codebase, fast connections and simple keys. wg-easy is a container that runs WireGuard together with a web interface for creating, naming, enabling and deleting peers, and for generating QR codes and configuration files for phones and laptops. This stack runs wg-easy on one host, stores the peer database in a named volume, and keeps the admin interface on localhost so only the WireGuard port is public.

Use this stack when you want a private network for your own devices, a way to reach home or office services from outside, or a secure path into a server without opening SSH to the internet. It suits a few dozen peers managed by one administrator. Do not use it to route traffic for a large group of unknown users, because you then need proper logging and identity management. Do not use it on a host where you cannot grant the NET_ADMIN and SYS_MODULE capabilities, since the container needs them to create the network interface. Also remember that the VPN is only as safe as the admin password, so use a strong one and revoke peers you no longer use.

docker-compose.yml

services:
  wg-easy:
    image: ghcr.io/wg-easy/wg-easy:14
    restart: unless-stopped
    environment:
      WG_HOST: ${WG_HOST}
      PASSWORD_HASH: ${PASSWORD_HASH}
      WG_DEFAULT_DNS: ${WG_DEFAULT_DNS}
    ports:
      - "${WG_PORT}:51820/udp"
      - "127.0.0.1:${WG_UI_PORT}:51821/tcp"
    volumes:
      - wg_easy_data:/etc/wireguard
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    sysctls:
      - net.ipv4.ip_forward=1
      - net.ipv4.conf.all.src_valid_mark=1

volumes:
  wg_easy_data:

.env

.env
# Public IP address or DNS name that clients connect to
WG_HOST=CHANGE_ME_vpn.example.com

# bcrypt hash of the UI password. Every $ must be written as $$ in this file.
PASSWORD_HASH=CHANGE_ME_bcrypt_hash_with_dollar_signs_doubled

# DNS server pushed to clients
WG_DEFAULT_DNS=1.1.1.1

# Public UDP port for WireGuard, and the localhost port for the web UI
WG_PORT=51820
WG_UI_PORT=51821

Start and verify

Shell
# 1. Generate the password hash for the UI (replace YOUR_PASSWORD).
#    Copy the output into .env and double every $ sign.
docker run --rm ghcr.io/wg-easy/wg-easy wgpw 'YOUR_PASSWORD'

# 2. Validate and start
docker compose config --quiet
docker compose up -d
docker compose ps
docker compose logs --tail=50 wg-easy

# 3. Verify the UI answers on localhost and the UDP port is listening
curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:51821/
sudo ss -ulpn | grep 51820

# 4. Verify forwarding inside the container
docker compose exec wg-easy cat /proc/sys/net/ipv4/ip_forward

From your own computer, open an SSH tunnel with ssh -L 51821:127.0.0.1:51821 youruser@your-server, browse to http://localhost:51821, create a client, and connect it with the WireGuard app. The forwarding check should print 1.

Production checklist

  • Publish only UDP 51820 to the internet, and keep the web UI bound to 127.0.0.1 behind an SSH tunnel or an authenticated HTTPS proxy.
  • NET_ADMIN and SYS_MODULE give the container power over the host network stack. Keep the image pinned, update it promptly, and do not run other containers with the same capabilities.
  • Use a long UI password and hash it with wgpw. Do not store the plain password in .env.
  • Open 51820/udp in the cloud provider firewall as well as the host firewall, or handshakes will never complete.
  • Use split tunnelling (narrow AllowedIPs) if you do not want all client traffic routed through the server, which reduces load and exposure.
  • Delete or disable the peer of any lost or retired device, and reissue configs when a device changes owner.
  • Back up wg_easy_data. Losing it creates new server keys and every client must be configured again.
  • Check that the image tag exists on ghcr.io before the first deploy, and read the release notes before changing the major version, since the configuration format can change.

Common problems

  • Symptom: Clients connect, but traffic does not reach the internet. Cause: IP forwarding or NAT is disabled on the host or in the container. Fix: Check the forwarding value with docker compose exec wg-easy cat /proc/sys/net/ipv4/ip_forward and confirm the sysctls section.
  • Symptom: The handshake never completes. Cause: The UDP port is blocked by a firewall, or WG_HOST does not resolve to the server. Fix: Open 51820/udp in every firewall layer and verify the DNS name from outside the server.
  • Symptom: The container exits with an error about creating the interface or operation not permitted. Cause: The NET_ADMIN or SYS_MODULE capability is missing, or the kernel lacks WireGuard support. Fix: Restore the cap_add section and check the host kernel with lsmod | grep wireguard.
  • Symptom: Every password is rejected in the UI. Cause: The dollar signs in PASSWORD_HASH were not doubled, so Compose substituted part of the hash. Fix: Double each dollar sign in .env and run docker compose up -d again.
  • Symptom: All peers stop working after an update. Cause: The wg_easy_data volume was removed or replaced by a new empty volume. Fix: Restore the volume from a backup, since a new one creates new server keys.

Variations

  • Split tunnel: Set the client AllowedIPs to a private range such as your home network, so only that traffic uses the VPN while the rest of the device traffic goes direct.
  • DNS filtering: Point WG_DEFAULT_DNS at a local resolver such as Pi-hole on the VPN network, so the clients get filtered DNS while connected.
  • Plain WireGuard on the host: If you prefer fewer moving parts, run WireGuard with wg-quick on the host instead of a container, and keep the same firewall and key rules.

Questions

Why does the UI reject my password?

Compose reads a dollar sign as the start of a variable. Every dollar sign in the bcrypt hash must be doubled in .env, or the hash is cut short and no password matches.

Why do clients connect but have no internet access?

IP forwarding or NAT is not active. The sysctls in this stack enable forwarding inside the container, so check that the container can reach the internet and that WG_DEFAULT_DNS is reachable.

Do I need to open the admin port to reach the UI?

No. The UI is bound to 127.0.0.1, so you reach it through an SSH tunnel. Only the WireGuard UDP port needs to be open to the internet.

Why do all clients need new configs after a recreate?

The keys and peer list are stored in the wg_easy_data volume. Removing that volume creates new keys, so keep it and back it up.

Adapt this stack

Load these files into the builder to rename services, change ports, add a cache or a proxy, and generate fresh passwords for the .env.

Open in builder
  • Caddy 2 Reverse Proxy + Static Web Server

    Caddy 2 in Docker Compose: serve a static site, proxy /api to a backend and get automatic HTTPS on a real domain. Pinned images and .env configuration.

    • caddy
    • whoami
    Difficulty: Beginner
  • Gitea Git Server with PostgreSQL 16

    Self-hosted Gitea with PostgreSQL 16 in Docker Compose: web Git hosting, SSH on port 2222, a healthcheck-gated database start and persistent volumes.

    • gitea
    • db
    Difficulty: Intermediate
  • Loki, Promtail and Grafana Log Stack

    Collect Linux host logs with Loki and Promtail in Docker Compose and query them in Grafana. Pinned images, persistent volumes and a localhost-only Grafana port.

    • loki
    • promtail
    • grafana
    Difficulty: Intermediate
  • Portainer CE Web UI for Docker Management

    Run Portainer CE in Docker Compose as a web UI for containers, images and volumes. Bound to localhost on HTTPS 9443, with persistent data and a pinned image.

    • portainer
    Difficulty: Intermediate

Browse more Infrastructure & Monitoring stacks or the full library.