Home Linux ServerTools How to install WireGuard with Docker Compose on Ubuntu 22.04

How to install WireGuard with Docker Compose on Ubuntu 22.04

by Thạch Phạm
Published: Last Updated on
A+A-
Reset

Installing WireGuard with Docker Compose on Ubuntu 22.04 with 6 steps.

Introduction

Like OpenVPN or IPSec, WireGuard is a free VPN system that helps you establish an encrypted connection between the client and the server via an Internet connection. WireGuard operates at layer 3, designed as a virtual network interface of the Kernel for Linux. WireGuard was created as an alternative to IPSec in most use cases and relied on TLS-based solutions like OpenVPN, while WireGuard is more secure, faster, and easier to use.

And in this article, AZDIGI will guide you to install WireGuard with Docker Compose on Ubuntu 22.04, please follow along.

Conditions the server needs to meet:

  1. Linux server (In this article, I will install on Ubuntu 22.04)
  2. Install Docker
  3. Install Docker Compose
  4. Public IP

If the above conditions are met, we will proceed to install and configure WireGuard.

Implementation Guide

Step 1: Install WireGuard

  • First, you need to create a folder containing the project and name it to your liking. For example, I will name it WireGuard
AZDIGI Tutorial
mkdir /home/WireGuard/.wg-easy
cd /home/WireGuard/.wg-easy
    
  • Next, download the file docker-compose.yml fromWeeJeWel/wg-easy on github with the command below:
AZDIGI Tutorial
wget https://raw.githubusercontent.com/WeeJeWel/wg-easy/master/docker-compose.yml
    
How to install WireGuard with Docker Compose on Ubuntu 22.04
  • Edit access path and WireGuard UI login information

To edit the WireGuard UI login information, proceed to edit the content of the docker-compose.yml file as follows:

AZDIGI Tutorial
sudo nano docker-compose.yml
    

You find and edit the User/Password information to the information you want and save it.

- WG_HOST= Nhập tên miền bạn muốn truy cập vào Web UI
- PASWORD= Nhập mật khẩu đăng nhập Web UI

For example, I set WG_HOST to wireguard.azdigi.space and PASSWORD to wireguard_passwd.

How to install WireGuard with Docker Compose on Ubuntu 22.04

Step 2: Enable WireGuard

After editing the information is complete, now run the command below to enable WireGuard:

AZDIGI Tutorial
docker-compose up --detach
    

The run will take a few minutes, and if successful, you will receive a message below:

How to install WireGuard with Docker Compose on Ubuntu 22.04

Now go to the browser and use the address <a href=”http://http://Server-IP:51821 or the previously set WG_HOST address to access WireGuard UI. have configured WG_HOST with the address wireguard.azdigi.space, so I will go to http://wireguard.azdigi.space:51821.

Now, you log in with the information declared in the PASSWORD section of the docker-compose.yml file.

How to install WireGuard with Docker Compose on Ubuntu 22.04

After successful login, you will see the WireGuard UI interface as below:

How to install WireGuard with Docker Compose on Ubuntu 22.04

Step 3: Create WireGuard Client

As you can see the WireGuard management Web UI interface is extremely friendly and easy to use. Here are some features you need to keep in mind when using Web UI:

  • Create WireGuard Client

To create a new Client, you need to click New Client => give it a name => click Create.

How to install WireGuard with Docker Compose on Ubuntu 22.04
  • Click on the QR icon to see the QR code used to set up the WireGuard client on your phone.
  • Click the Download icon to download the configuration file, which is used to set up the WireGuard client on the computer.
  • Click the Trash icon to delete the client.
How to install WireGuard with Docker Compose on Ubuntu 22.04

Step 4: Configure NAT Port for WireGuard

To be able to connect to the WireGuard VPN Server from the outside, you must configure the open port on the network router (if WireGuard is installed on the server at home), or configure the firewall if installed on the virtual server.

Here I’m installing it to a VPS service at AZDIGI, so I will open port 51820 on VPS with the following command:

AZDIGI Tutorial
sudo ufw allow 51820/udp
    

Step 5: Setup & use WireGuard

1. Set up & use WireGuard on the computer

Before setting up, you need to have the WireGuard application. And you can download WireGuard from the WireGuard homepage for operating system platforms:

  • Download the WireGuard application on Windows here
  • Download the WireGuard application on MacOS here

After downloading and installing the WireGuard software application on the client computer, click the + sign => select Import Tunnel(s) from File to add configuration.

How to install WireGuard with Docker Compose on Ubuntu 22.04
CleanShot 2022 05 22 at 00.15.05

2. Set up & use WireGuard on mobile

WireGuard is also available on mobile devices. To download, please visit the corresponding link below:

  • Download the WireGuard app on AppStore here
  • Download the WireGuard application on Google Play here
How to install WireGuard with Docker Compose on Ubuntu 22.04
  • Create from QR code: Scan the QR code.
  • Create from file or archive: Import the configuration file.
How to install WireGuard with Docker Compose on Ubuntu 22.04

Step 6: Check the internet connection

After the connection is complete, I will access the Internet to check if it works and if the IP is correct.

How to install WireGuard with Docker Compose on Ubuntu 22.04

So AZDIGI has completed installing WireGuard with Docker Compose on Ubuntu 22.04. Wishing you success!

You can refer to other user manuals at the link below

If you need support, you can contact support in the ways below:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign