OpenVPN Server containerized
1.2K
OpenVPN server in a Docker container, complete with an EasyRSA PKI certificate authority. Run a full VPN server — keys, certs, and config included — in a single self-contained image.
Maintained fork. This is an actively maintained fork of
kylemanna/docker-openvpn, which appears to be unmaintained. This image keeps the codebase current, applies fixes, and adds improvements on top of the original work. Source: github.com/yukifolf/docker-openvpn
latest — current stable build<version> — pinned release tags (recommended for production).ovpn file.tun mode and net30 topology for the widest device and OS compatibility, including Android and Windows.Replace VPN.SERVERNAME.COM with your server's public hostname or IP.
1. Pick a data volume name (the ovpn-data- prefix works seamlessly with the reference systemd service):
OVPN_DATA="ovpn-data-example"
2. Initialize config and the PKI (you'll be prompted for a CA passphrase):
docker volume create --name $OVPN_DATA
docker run -v $OVPN_DATA:/etc/openvpn --rm yukifolf/docker-openvpn:tagname ovpn_genconfig -u udp://VPN.SERVERNAME.COM
docker run -v $OVPN_DATA:/etc/openvpn --rm -it yukifolf/docker-openvpn:tagname ovpn_initpki
3. Start the server:
docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN yukifolf/docker-openvpn:tagname
4. Generate a client certificate (omit nopass to protect the client key with a passphrase):
docker run -v $OVPN_DATA:/etc/openvpn --rm -it yukifolf/docker-openvpn:tagname easyrsa build-client-full CLIENTNAME nopass
5. Export the client profile:
docker run -v $OVPN_DATA:/etc/openvpn --rm yukifolf/docker-openvpn:tagname ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
Hand CLIENTNAME.ovpn to the client and connect with openvpn --config CLIENTNAME.ovpn.
On initialization the image generates Diffie-Hellman parameters, a server private key and matching self-certificate, an EasyRSA CA key and certificate, and a TLS-auth HMAC key. All of this — config and PKI — is stored under /etc/openvpn, which is declared as a volume so it persists and can be backed up. The server runs via the default ovpn_run command. By default the UDP server hands out 192.168.255.0/24 to dynamic clients, and client profiles use redirect-gateway def1 so all traffic flows through the VPN once connected.
OTP-based 2FA for clients is supported. See the OTP documentation in the docs folder.
More advanced configuration — Docker Compose, systemd init scripts, static client IPs, and other write-ups — is available in the docs folder of the GitHub repository.
The container runs its own EasyRSA PKI CA, trading some security for convenience under the assumption that the host is trusted — anyone with access to the PKI files under /etc/openvpn/pki could compromise the server. Recommendations:
ovpn_copy_server_files can move server files off the signing host.build-client-full leaves client keys on the server; treat the host filesystem accordingly.Assuming the host filesystem is secure, TLS + PKI prevents any unauthorized host from using the VPN.
Based on the original work by Kyle Manna. This fork is maintained by Wojciech Szyjka with ongoing improvements and updates.
Source code and issues: github.com/yukifolf/docker-openvpn
Content type
Image
Digest
sha256:a43c7bf83…
Size
7.2 MB
Last updated
3 months ago
docker pull yukifolf/docker-openvpn