Lightweight OpenVPN Community Edition server with uninitialized pki.
364
This is a lightweight OpenVPN Community Edition server image. It comes with an uninitialized Public Key Infrastructure (PKI), giving you complete control over your certificate management and initial setup.
Because the PKI is uninitialized, setting up the server requires a one-time manual configuration before it can run automatically.
To begin, you need to keep the container awake without starting the OpenVPN daemon. You do this by overriding the default command with sleep infinity.
Important: You must mount a volume (or a local host directory) to /etc/openvpn so your generated PKI and configuration files are permanently saved.
docker run -d \
--name openvpn-init \
-v openvpn_data:/etc/openvpn \
teodornasu/openvpn-alpine:latest sleep infinity
(Note: Replace openvpn_data with a local path like /my/local/path:/etc/openvpn if you prefer bind mounts).
Once the container is running in sleep mode, open an interactive shell inside it to set up your keys:
docker exec -it openvpn-init /bin/sh
Inside the container, copy the easy-rsa binaries to your persistent directory and start building your PKI:
# Copy easyrsa binaries to the persistent OpenVPN directory
cp -r /usr/share/rasy-rsa/* /etc/openvpn/
# Navigate to the directory and run your PKI generation commands
cd /etc/openvpn
# (e.g., ./easyrsa init-pki, ./easyrsa build-ca, etc.)
To enable automatic starts, the server requires a configuration file (e.g., server.ovpn). Place your completed configuration file into the /etc/openvpn directory. Because you mounted this directory in Step 1, you can also drop this file directly into the corresponding folder on your host machine.
Once your PKI is fully generated and your configuration file is in place, you can stop and clean up the initialization container:
docker rm -f openvpn-init
Now, launch the server normally without the sleep infinity command. It will automatically detect the configuration in /etc/openvpn and start the service:
docker run -d \
--name openvpn-server \
--cap-add=NET_ADMIN \
-p 1194:1194/udp \
-v openvpn_data:/etc/openvpn \
teodornasu/openvpn-alpine:latest
(Note: OpenVPN typically requires the --cap-add=NET_ADMIN flag and port 1194 exposed to route traffic properly).
⚠️ IMPORTANT: Enable NAT Routing via Command Override
To allow VPN clients to access host services (like an SMB share), you must masquerade the container's outbound traffic. Without this, the clients might experience traffic collisions between subnets.
You must override the container's default startup command to apply an
iptablesrule before launching OpenVPN.For Docker Compose / TrueNAS, add this line:
command: ["sh", "-c", "iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE && openvpn --config server.ovpn"](For CLI
docker run, simply append the string inside the brackets to the end of your command).
Content type
Image
Digest
sha256:e2567c7fa…
Size
5.7 MB
Last updated
5 months ago
docker pull teodornasu/openvpn-alpine