Install WireGuard VPN on Docker Compose
Install WireGuard on Docker
WireGuard is a lightweight and efficient VPN solution known for its simplicity and performance. By running WireGuard in a Docker container, you can simplify deployment and management. This guide walks you through the steps to set up WireGuard using Docker and Docker Compose, including both server and client configurations.
Step 1: Install Docker
If Docker is not already installed on your server, follow these steps:
Start the Docker service:
Step 2: Install Docker Compose
Download the Docker Compose binary:
Make Docker Compose executable:
Verify the installation:
Check that Docker is running:
Step 3: Set Up WireGuard Directory
Create a directory for your WireGuard setup:
Inside the wireguard/
directory, create a configuration directory:
Step 4: Create the Docker Compose File
Using your preferred text editor, create the docker-compose.yml
file:
Add the following content:
Step 5: Start the WireGuard Container
Run the following command to start the WireGuard container:
Verify the running container:
Check the container logs for additional details:
Step 6: Access Configuration Files
The WireGuard configuration files for the server and peers are stored in the config/wireguard
directory. Navigate to this directory:
Each peer will have its own configuration folder, such as peer1
. To view the configuration for a specific peer, navigate to its directory:
View the peer’s configuration file:
Example peer1.conf
file:
Step 7: Set Up the Client
Install WireGuard Client
Import the Configuration
Open the WireGuard client.
Click Import Tunnel.
Select the configuration file (e.g.,
peer1.conf
).Activate the tunnel to connect to the WireGuard VPN.
Step 8: Test the Connection
Once the client is connected, verify that traffic is routed through the VPN by checking your public IP address:
If the IP matches your server’s public IP, the VPN is working correctly.
Notes
Ensure that port
51820/udp
is open in your server’s firewall or security group.Modify the
PEERS
environment variable in thedocker-compose.yml
file to generate multiple client configurations.Restart the WireGuard container if you make changes to the configuration.
By following these steps, you can deploy a WireGuard VPN server on Docker with ease. Enjoy the security and performance of WireGuard for your networking needs!
Last updated