Setting up your own OpenVPN server using Docker is an efficient way to ensure secure, private, and scalable VPN access for personal or business use. This guide walks you through deploying an OpenVPN server with Docker Compose, generating client profiles, and connecting from various devices.
Setup OpenVPN Server via Docker
Prerequisites
Ensure you have the following:
- A Linux server (e.g., Ubuntu 20.04) with Docker and Docker Compose installed.
- A public IP address or domain name pointing to your server.
- Ports 1194/UDP open on your firewall.OpenVPNMedium
Step 1: Create the Docker Compose File
In your server’s terminal, create a directory for your OpenVPN setup and navigate into it:
mkdir ~/openvpn-docker
cd ~/openvpn-docker
Create a docker-compose.yml file with the following content:
version: '2'
services:
openvpn:
image: kylemanna/openvpn
container_name: openvpn
cap_add:
- NET_ADMIN
ports:
- "1194:1194/udp"
volumes:
- ./openvpn-data/conf:/etc/openvpn
restart: always
Step 2: Initialize the OpenVPN Configuration
Replace VPN.SERVERNAME.COM with your server’s domain name or IP address:Medium
docker-compose run --rm openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM
docker-compose run --rm openvpn ovpn_initpki
Set a passphrase when prompted.YouTube+1OpenVPN+1
Step 3: Adjust File Permissions
Ensure the current user owns the OpenVPN data directory:
sudo chown -R $(whoami): ./openvpn-data
Step 4: Start the OpenVPN Server
Launch the OpenVPN server container:
docker-compose up -d openvpn
Check the logs to verify the server is running:
docker-compose logs -f
Step 5: Generate Client Certificates and Configuration
Replace your_client_name with a desired client identifier:
export CLIENTNAME="your_client_name"
docker-compose run --rm openvpn easyrsa build-client-full $CLIENTNAME
docker-compose run --rm openvpn ovpn_getclient $CLIENTNAME > $CLIENTNAME.ovpn
Transfer the $CLIENTNAME.ovpn file to the client device.Medium
Connecting to Your OpenVPN Server
Windows
- Download and install the OpenVPN Connect client for Windows.
- Launch the application and import the
.ovpnfile. - Connect to the VPN by selecting the profile and clicking “Connect”.OpenVPN+8TP-Link+8OpenVPN+8Stack Overflow+2OpenVPN+2OpenVPN+2
macOS
- Download and install the OpenVPN Connect client for macOS.
- Open the application and import the
.ovpnfile. - Connect to the VPN by selecting the profile and clicking “Connect”.
Android
- Install the OpenVPN Connect app from Google Play.
- Transfer the
.ovpnfile to your device. - Open the app, tap the “+” icon, and import the profile.
- Connect to the VPN by selecting the profile.OpenVPN
iOS
- Install the OpenVPN Connect app from the App Store.
- Transfer the
.ovpnfile to your device via email or cloud storage. - Open the file with OpenVPN Connect to import the profile.
- Connect to the VPN by selecting the profile.Apple
Frequently Asked Questions (FAQ)
Can I use TCP instead of UDP?
Yes, modify the docker-compose.yml and replace 1194:1194/udp with 1194:1194/tcp, and adjust the protocol in the ovpn_genconfig command accordingly.
How do I revoke a client certificate?
Run the following command:
docker-compose run --rm openvpn ovpn_revokeclient $CLIENTNAME remove
Is it safe to run this setup in production?
Yes, but ensure you keep your Docker and OpenVPN images up to date, use strong passwords, and monitor your server for unauthorized access.
Can I manage multiple clients?
Absolutely. Repeat the client certificate generation steps for each user, assigning unique CLIENTNAME values.
By following this guide, you can deploy a secure OpenVPN server using Docker, providing encrypted access to your network resources from various devices.
Try Vpnymous for Effortless, Private VPN Access
Setting up your own OpenVPN server is a powerful way to gain full control over your online privacy — but it’s not for everyone. If you prefer to skip the manual setup and still enjoy secure, anonymous internet access, Vpnymous has you covered.
– Instant OpenVPN access with zero technical overhead
– No personal data required — just pay with crypto and connect
– No logs. No tracking. No limits. Ever.
– Works on all major platforms including Windows, macOS, Linux, Android, and iOS
👉 Ready to skip the hassle? Buy VPN with crypto now
Related Guides:
What is a Remote Access VPN and How Does It Work?