Skip to content
SumGuy's Ramblings
Go back

Wireguard VPN Server in Docker

Install Docker

Install docker on Ubuntu/DebianInstall docker on Ubuntu/Debian

Why Wireguard

WireGuard VPN is a newer VPN protocol that is designed to be faster, more secure, and simpler than older VPN protocols such as OpenVPN. WireGuard uses modern cryptographic techniques to provide better security and performance compared to other VPN protocols. Here are some of the main advantages of using WireGuard VPN over OpenVPN:

In summary, WireGuard VPN offers faster speeds, better security, simpler configuration, and improved battery life compared to OpenVPN. These advantages make WireGuard a great choice for users who want a faster and more secure VPN experience. However, it should be noted that WireGuard is still a relatively new protocol and may not be as widely supported as OpenVPN by VPN providers and clients.

Create docker-compose.yml

Create a new directory for your project and create a file named docker-compose.yml inside it. add the following to it.

---
version: "2"
services:
  wireguard:
    image: lscr.io/linuxserver/wireguard:latest
    container_name: wireguard
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC  # e.g. America/New_York
      - SERVERURL=wireguard.domain.com #External IP or domain name for docker host. can be auto, the container will determine the IP
      - SERVERPORT=51820 # server port
      - PEERS=desktop,tablet,phone,phone2,fridge,toaster,cat_collar #names of all devices you want to add to this vpn
      - PEERDNS=1.1.1.1 #dns server IP to use with wireguard (cloduflare shown)
      - INTERNAL_SUBNET=10.13.13.0 #your internal subnet for the VPN
      - ALLOWEDIPS=0.0.0.0/0 # what IPs can connect to your server? leave at 0.0.0.0 unless you have a specific reason.
      - PERSISTENTKEEPALIVE_PEERS= #optional
      - LOG_CONFS=true # Generated QR codes will be displayed in the docker log.
    volumes:
      - ./config:/config
    #  - /lib/modules:/lib/modules # only enable if using custom wireguard modules.
    ports:
      - 51820:51820/udp
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
    restart: unless-stopped

the ENV variables are explained in the comments but the rest of the commands are explained below :

Operations

docker compose up -d : download images as needed and turn on the container. docker compose down : bring down the container and disable the network. leaves the volumes on disk.

More updated info can be found at : https://docs.linuxserver.io/images/docker-wireguard


Share this post on:

Previous Post
Appwrite Backend-as-a-service (BaaS)
Next Post
Install & use Doxygen via Docker