Docker Compose (Optional but Highly Recommended): Docker Compose simplifies the management of Docker containers. It's generally the easiest way to get wg-easy running long-term.
bash
sudo apt install docker-compose -y
2. Install wg-easy using Docker Compose (Recommended):
Create a Directory: Create a directory to store your Docker Compose configuration.
bash
mkdir -p /opt/wg-easy
cd /opt/wg-easy
Create docker-compose.yml: Create a docker-compose.yml file with the following content:
yaml
version: "3"
services:
wg-easy:
image: ghcr.io/wg-easy/wg-easy:latest
container_name: wg-easy
environment:
# ⚠️ Required:
WG_HOST: <YOUR_SERVER_IP> # Replace with your server's public IP address or domain name. Important!
# Optional:
WG_PORT: 51820 # Can be changed, but remember to forward this port in your firewall.
WG_DEFAULT_DNS: 1.1.1.1 # Cloudflare DNS
WG_PASSWORD: <YOUR_ADMIN_PASSWORD> #Set a password to manage wireguard from web browser.
# WG_ALLOWED_IPS: 192.168.30.0/24 # Set Allowed IP addresses,
volumes:
- ./data:/etc/wireguard
ports:
- "51820:51820/udp" # Wireguard port, do not change this
- "8080:8080" # WebUI port
sysctl:
- net.ipv4.ip_forward=1
- net.ipv4.conf.all.src_valid_mark=1
cap_add:
- NET_ADMIN
restart: unless-stopped
Important Notes:
WG_HOST: Replace <YOUR_SERVER_IP> with your server's public IP address or a domain name that resolves to your server. This is absolutely crucial. If you're behind a NAT, this should be the public IP of your router. If you have a domain pointing to your server, use that.
WG_PASSWORD: Replace <YOUR_ADMIN_PASSWORD> with a strong password for accessing the wg-easy web interface. This is used to create and manage your WireGuard users. Do not leave this blank!
WG_PORT:51820 is the default WireGuard port. You can change it, but you'll need to forward the new port in your firewall and router (if applicable).
WG_DEFAULT_DNS: I've set this to Cloudflare's DNS (1.1.1.1) but you can use another DNS server (e.g., Google DNS: 8.8.8.8).
./data:/etc/wireguard: This line mounts the ./data directory on your host machine (in /opt/wg-easy/data) to the /etc/wireguard directory inside the container. This is where WireGuard configuration files will be stored, making them persistent even if the container is restarted. Do not modify this.
Firewall: Make sure that your firewall (e.g., ufw on Ubuntu) allows UDP traffic on the port you've configured (default: 51820). See step 3 below.
Start the Container: Start the wg-easy container using Docker Compose:
bash
docker-compose up -d
This will download the wg-easy image and start the container in detached mode (in the background).
3. Configure the Firewall (UFW - Ubuntu Firewall):
If you have ufw enabled (the default on Ubuntu Server), you need to allow UDP traffic on the WireGuard port (51820 by default) and the web UI port (8080 by default):
bash
sudo ufw allow 51820/udp
sudo ufw allow 8080
sudo ufw enable # If not already enabled
sudo ufw status
4. Access the Web Interface:
Open your web browser and go to http://<YOUR_SERVER_IP>:8080 or http://<YOUR_DOMAIN>:8080.
Log in using the password you set in the WG_PASSWORD environment variable in your docker-compose.yml file.
5. Create a User:
In the wg-easy web interface:
Click "New" or "Create Client".
A new configuration file will be generated for the user.
Download the .conf file or use the provided QR code to easily configure the WireGuard client on the user's device.
6. Configure WireGuard Client:
Install WireGuard Client: Install the WireGuard client on the user's device (available for Windows, macOS, Linux, Android, and iOS).
Import Configuration: Import the downloaded .conf file into the WireGuard client. On most platforms, there is an "Import from file" or "Add Tunnel" option.
Activate Connection: Activate the WireGuard connection.
7. Profit:
The user should now be connected to the WireGuard VPN.
Explanation and Troubleshooting:
Docker: Docker isolates applications into containers, making them easier to deploy and manage.
Docker Compose: Docker Compose allows you to define and manage multi-container Docker applications using a docker-compose.yml file. This is easier than running long docker run commands manually.
wg-easy: This Docker image provides a simple web interface for managing WireGuard users. It automatically handles key generation and configuration file creation.
WG_HOST: This is the most important setting. If it's incorrect, clients won't be able to connect. Make sure it's the public IP or domain name that clients will use to reach your server.
Firewall: The firewall must allow UDP traffic on the WireGuard port (51820 by default). Without this, connections will be blocked. Also allow the web UI port (8080) so you can access the admin interface.
Router: If your server is behind a router, you'll need to configure port forwarding on the router to forward UDP traffic on the WireGuard port (51820 by default) to your server's internal IP address.
Web UI Access: If you can't access the web UI, make sure the Docker container is running (docker ps), the firewall is configured correctly, and you're using the correct IP address and port (8080).
Client Connection Issues:
Double-check the WG_HOST value in your docker-compose.yml file.
Verify the firewall and router port forwarding rules.
Make sure the client's configuration file (.conf) is imported correctly and the connection is activated.
Check the WireGuard client logs for any error messages.
Verify that your local networks do not conflict. By default, wg-easy will setup a network on 10.6.0.0/24. If your local network is on the same range, you may need to adjust the server config, and the client config as well. This is more complicated, but should be mentioned as it can cause issues.
Using docker run (Less Recommended):
If you don't want to use Docker Compose, you can run the wg-easy container directly with docker run. This is less convenient but still works:
Replace <YOUR_SERVER_IP> and <YOUR_ADMIN_PASSWORD> as described above. The /opt/wg-easy/data directory will store your WireGuard configuration files. Remember to configure your firewall (ufw) as described in step 3.
Using Docker Compose is generally the preferred method for managing Docker containers. It makes it easier to update, restart, and configure your application. The wg-easy image simplifies WireGuard setup and user management considerably.