Self-hosted OpenVPN server in Docker with automatic PKI bootstrap and client management.
1.1K
Self-hosted OpenVPN server in Docker with automatic PKI bootstrap, modern TLS
settings, per-client tls-crypt-v2 keys, client revocation, nftables NAT, and
multi-architecture Alpine/Debian images.
| Registry | Image | Use |
|---|---|---|
| GHCR | ghcr.io/holms/docker-openvpn | Primary/default; no Docker Hub anonymous rate limits |
| Docker Hub | holms/docker-openvpn | Mirror |
All published tags are multi-architecture (linux/amd64 and linux/arm64).
| Tag example | Base image | Meaning |
|---|---|---|
latest | Alpine | Latest release, rolling tag |
alpine | Alpine | Latest Alpine build, rolling tag |
debian | Debian | Latest Debian build, rolling tag |
1.0.0 | Alpine | Release 1.0.0 default variant |
1.0.0-alpine | Alpine 3.24 | Release 1.0.0, Alpine variant |
1.0.0-debian | Debian 13 slim | Release 1.0.0, Debian variant |
For new releases, replace 1.0.0 with the release version. The unqualified
version tag always uses the smaller Alpine variant. Pin an exact variant tag in
production.
docker compose version)/dev/net/tun)UDP 1194 is the default and recommended port/protocol.
git clone https://github.com/holms/docker-openvpn.git
cd docker-openvpn
cp .env.example .env
Edit .env and set the public endpoint:
VPN_DNS_NAME=vpn.example.com
Start the server and export the first client:
./vpnctl up
./vpnctl export client
Import clients/client.ovpn into OpenVPN Connect, Tunnelblick, or another
OpenVPN 2.5+ client. The .ovpn file contains a private key; distribute it
securely and do not commit it.
If neither VPN_DNS_NAME nor VPN_PUBLIC_IP is set, first boot tries to
auto-detect the host's public IPv4 address. A DNS name is strongly recommended.
| Command | Purpose |
|---|---|
./vpnctl add alice | Create and export clients/alice.ovpn |
./vpnctl export alice | Export/refresh clients/alice.ovpn |
./vpnctl list | List valid client certificates and their static IPs |
./vpnctl revoke alice | Revoke a client after confirmation |
./vpnctl revoke alice --yes | Revoke without prompting |
./vpnctl setip alice 10.8.0.200 | Assign a static VPN IP to a client |
./vpnctl unsetip alice | Remove a client's static IP assignment |
./vpnctl status | Show connected clients (refreshes every 10 seconds) |
Revoking also deletes clients/alice.ovpn on the host and the client's static
IP assignment inside the container.
Issue one certificate per device or person. Reusing the same certificate on multiple simultaneous connections causes sessions to displace each other.
The usable tunnel addresses are split in half: the first half is the dynamic
pool handed out to ordinary clients, and the second half is reserved for static
assignments. For the default 10.8.0.0/24 subnet the dynamic pool is
10.8.0.2–10.8.0.127 and the static range is 10.8.0.128–10.8.0.254.
./vpnctl setip alice 10.8.0.200
The IP must come from the static range and cannot be assigned to two clients at
once. The change takes effect on the client's next connection; no server
restart is needed. ./vpnctl unsetip alice returns the client to the dynamic
pool. Subnets smaller than /29 have no room for a split, so static IPs are
unavailable there.
| Command | Purpose |
|---|---|
./vpnctl up | Start using the configured/published image |
./vpnctl up --build | Force a local image build |
./vpnctl pull | Pull the configured image |
./vpnctl logs | Follow server logs |
./vpnctl ps | Show Compose service status |
./vpnctl doctor | Run host and container diagnostics |
./vpnctl restart | Restart the OpenVPN container |
./vpnctl down | Stop/remove the container, keeping the volume |
./vpnctl shell | Open a shell in the running container |
Configuration is in .env:
| Variable | Default | Meaning |
|---|---|---|
VPN_DNS_NAME | empty | Public DNS name used by clients |
VPN_PUBLIC_IP | empty | Public IPv4 address if DNS is not used |
VPN_PROTO | udp | udp or tcp |
VPN_PORT | 1194 | External and internal VPN port |
VPN_CLIENT_NAME | client | First client certificate/profile |
VPN_DNS_SRV1 / VPN_DNS_SRV2 | 1.1.1.1 / 1.0.0.1 | DNS servers pushed to clients |
VPN_SUBNET | 10.8.0.0/24 | IPv4 tunnel network |
VPN_FULL_TUNNEL | true | Route all client traffic through the VPN |
VPN_BLOCK_IPV6 | true | In full-tunnel mode, stop client IPv6 traffic from bypassing the VPN |
VPN_PUSH_ROUTES | empty | Comma-separated CIDRs for split tunneling |
VPN_CLIENT_TO_CLIENT | false | Allow VPN clients to reach each other |
VPN_ENABLE_NAT | true | Masquerade VPN traffic leaving the container |
VPN_KEY_SIZE | 3072 | RSA key size for newly generated certificates |
VPN_CERT_DAYS | 3650 | Server/client certificate lifetime |
VPN_CA_DAYS | 3650 | CA certificate lifetime |
VPN_CA_NAME | OpenVPN-CA | CA certificate common name |
OPENVPN_IMAGE | ghcr.io/holms/docker-openvpn:latest | Image reference to run |
OPENVPN_DOCKERFILE | Dockerfile | Local build variant: Dockerfile or Dockerfile.debian |
ALPINE_VERSION | 3.24 | Alpine base for local Alpine builds |
DEBIAN_VERSION | 13-slim | Debian base for local Debian builds |
After changing .env, recreate the service and export updated client profiles:
./vpnctl up
./vpnctl export client
For a split tunnel, set VPN_FULL_TUNNEL=false and list only the networks that
should use the VPN:
VPN_FULL_TUNNEL=false
VPN_PUSH_ROUTES=192.168.10.0/24,192.168.20.0/24
The tunnel carries IPv4 only. On a dual-stack network (common on home and
mobile connections) a client would otherwise reach IPv6-enabled sites directly,
bypassing the VPN. When VPN_FULL_TUNNEL=true, VPN_BLOCK_IPV6=true (the
default) routes client IPv6 into the tunnel and rejects it there, so
applications fall back to IPv4 through the VPN. Set it to false if clients
must keep reaching the Internet over their own IPv6. It has no effect on
split-tunnel setups.
Pin an exact variant in .env:
OPENVPN_IMAGE=ghcr.io/holms/docker-openvpn:1.0.0-alpine
Then update deliberately:
./vpnctl pull
./vpnctl up
To use the Docker Hub mirror instead, replace the image prefix with
holms/docker-openvpn.
Alpine is the default local build:
./vpnctl up --build
Debian local build:
OPENVPN_DOCKERFILE=Dockerfile.debian
Then run:
./vpnctl up --build
The container:
VPN_PORT/VPN_PROTO on the host,VPN_SUBNET, andThis does not open the external firewall or cloud security-group port for you. For the default configuration, allow inbound UDP 1194 to the host.
Run diagnostics first:
./vpnctl doctor
./vpnctl logs
| Symptom | Likely cause and fix |
|---|---|
/dev/net/tun is not available | Run sudo modprobe tun on the host, or enable TUN/TAP in the VPS control panel |
| Clients time out | Check public DNS/IP, host firewall, cloud security group, and router forwarding |
| UDP port is open but TCP was tested | UDP and TCP firewall rules are different; test/open the correct protocol |
| Clients connect without internet | Check VPN_SUBNET overlap, VPN_ENABLE_NAT, and NAT errors in logs |
| Config changes have no effect | Recreate with ./vpnctl up and export new client profiles |
| Rootless container cannot start | Rootless runtimes may block TUN or nftables; use normal rootful Docker on Linux |
| Old client cannot connect | Use an OpenVPN 2.5+ client with tls-crypt-v2 support |
.ovpn files contain private keys. Treat them as secrets.Back up the Compose openvpn-data volume before upgrades or migration. It
contains the CA, certificates, keys, CRL state, and generated client profiles.
While the container is running, one simple backup method is:
backup_dir="backups/openvpn-$(date +%Y%m%d%H%M%S)"
mkdir -p "$backup_dir"
docker cp "$(docker compose ps -q openvpn):/etc/openvpn/." "$backup_dir/"
chmod 700 "$backup_dir"
Resetting the volume creates a completely new VPN identity and invalidates all existing clients. Do not remove it unless that is intentional.
The release workflow is tag-only:
git tag vX.Y.Z
git push origin vX.Y.Z
CI runs lint plus Alpine/Debian smoke tests, then publishes both variants to
GHCR and Docker Hub. Docker Hub publishing uses the DOCKERHUB_TOKEN Actions
secret; GHCR uses the workflow GITHUB_TOKEN.
docker pull holms/docker-openvpn:latest