Skip to content

Instantly share code, notes, and snippets.

@avin
Last active May 6, 2024 17:34
Show Gist options
  • Save avin/b241a98fcff488ae1d62223eecc1044e to your computer and use it in GitHub Desktop.
Save avin/b241a98fcff488ae1d62223eecc1044e to your computer and use it in GitHub Desktop.
Wireguard via Docker

Prepare

sudo mkdir -p /opt/wireguard/config
sudo nano /opt/wireguard/docker-compose.yml

docker-compose.yml content:

---
services:
  wireguard:
    image: lscr.io/linuxserver/wireguard
    container_name: wireguard
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - SERVERURL=auto #optional
      - SERVERPORT=51820 #optional
      - PEERS=10 #optional
      - PEERDNS=auto #optional
      - INTERNAL_SUBNET=10.10.10.0 #optional
      - ALLOWEDIPS=0.0.0.0/0 #optional
    volumes:
      - /opt/wireguard/config:/config
      - /lib/modules:/lib/modules
    ports:
      - 51820:51820/udp
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
    restart: unless-stopped

Run

cd /opt/wireguard
sudo docker compose up -d

Show QR to connect

sudo docker exec -it wireguard /app/show-peer 1

Config to use on client /opt/wireguard/config/peerX/peerX.conf (where X is a serial number starting with 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment