Skip to content

Instantly share code, notes, and snippets.

@ohidurbappy
Created February 22, 2023 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohidurbappy/4bc229d6a586ad0108bc4da68b00ee96 to your computer and use it in GitHub Desktop.
Save ohidurbappy/4bc229d6a586ad0108bc4da68b00ee96 to your computer and use it in GitHub Desktop.

Install docker on Ubuntu 22.04

 curl -fsSL https://get.docker.com -o get-docker.sh
 sudo sh get-docker.sh

Add user to the docker group

sudo usermod -aG docker $USER
newgrp docker

Install wireguard docker-compose.yml

---
version: "2.1"
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
      - SERVERURL=wireguard.domain.com #optional
      - SERVERPORT=51820 #optional
      - PEERS=1 #optional
      - PEERDNS=auto #optional
      - INTERNAL_SUBNET=10.13.13.0 #optional
      - ALLOWEDIPS=0.0.0.0/0 #optional
      - PERSISTENTKEEPALIVE_PEERS= #optional
      - LOG_CONFS=true #optional
    volumes:
      - /path/to/appdata/config:/config
      - /lib/modules:/lib/modules #optional
    ports:
      - 51820:51820/udp
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
    restart: unless-stopped

Run the container

docker compose up -d

Distribute the config files to clients

You could also use the docker image for your clients. But I think it's more practical for a client to install WireGuard directly on the host OS. If you want to know how to do that, you can also refer to my article about WireGuard installation and configuration on Linux.

When you have started the WireGuard container, it should automatically create all configuration files in your ./config folder. All you need to do is to copy the corresponding ./config/peer1/peer1.conf file to your client and use that as your wg0.conf, for instance. If you want to connect mobile phones you can also just scan the peer1.png QR code, to print the QR code to the console, simply use the following command:

docker exec -it wireguard /app/show-peer <peer-number>

to copy to other remote client

scp peer1.conf remote_username@remote_host:~/peer1.conf

and on the client ubuntu manchine move it to the right location

mv peer1.conf /etc/wireguard/wg0.conf
wg-quick up wg0

now we can check if it is connected. On the host server:

docker exec -it wireguard wg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment