HUB
Sign inSign up

holms/docker-openvpn

By holms

•Updated 4 days ago

Self-hosted OpenVPN server in Docker with automatic PKI bootstrap and client management.

Image
0

1.1K

holms/docker-openvpn repository overview

⁠docker-openvpn

CI Git tag Docker Hub pulls Docker image size GHCR

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.

⁠Images

RegistryImageUse
GHCRghcr.io/holms/docker-openvpnPrimary/default; no Docker Hub anonymous rate limits
Docker Hubholms/docker-openvpnMirror

All published tags are multi-architecture (linux/amd64 and linux/arm64).

⁠Tag reference
Tag exampleBase imageMeaning
latestAlpineLatest release, rolling tag
alpineAlpineLatest Alpine build, rolling tag
debianDebianLatest Debian build, rolling tag
1.0.0AlpineRelease 1.0.0 default variant
1.0.0-alpineAlpine 3.24Release 1.0.0, Alpine variant
1.0.0-debianDebian 13 slimRelease 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.

⁠Requirements

  • Linux server with Docker and Compose v2 (docker compose version)
  • Host kernel TUN/TAP support (/dev/net/tun)
  • Public IPv4 address or DNS name
  • VPN port open in the host firewall, cloud security group, or router NAT rule

UDP 1194 is the default and recommended port/protocol.

⁠Quick start

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.

⁠Client management

CommandPurpose
./vpnctl add aliceCreate and export clients/alice.ovpn
./vpnctl export aliceExport/refresh clients/alice.ovpn
./vpnctl listList valid client certificates and their static IPs
./vpnctl revoke aliceRevoke a client after confirmation
./vpnctl revoke alice --yesRevoke without prompting
./vpnctl setip alice 10.8.0.200Assign a static VPN IP to a client
./vpnctl unsetip aliceRemove a client's static IP assignment
./vpnctl statusShow 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.

⁠Static client IPs

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.

⁠Server commands

CommandPurpose
./vpnctl upStart using the configured/published image
./vpnctl up --buildForce a local image build
./vpnctl pullPull the configured image
./vpnctl logsFollow server logs
./vpnctl psShow Compose service status
./vpnctl doctorRun host and container diagnostics
./vpnctl restartRestart the OpenVPN container
./vpnctl downStop/remove the container, keeping the volume
./vpnctl shellOpen a shell in the running container

⁠Configuration

Configuration is in .env:

VariableDefaultMeaning
VPN_DNS_NAMEemptyPublic DNS name used by clients
VPN_PUBLIC_IPemptyPublic IPv4 address if DNS is not used
VPN_PROTOudpudp or tcp
VPN_PORT1194External and internal VPN port
VPN_CLIENT_NAMEclientFirst client certificate/profile
VPN_DNS_SRV1 / VPN_DNS_SRV21.1.1.1 / 1.0.0.1DNS servers pushed to clients
VPN_SUBNET10.8.0.0/24IPv4 tunnel network
VPN_FULL_TUNNELtrueRoute all client traffic through the VPN
VPN_BLOCK_IPV6trueIn full-tunnel mode, stop client IPv6 traffic from bypassing the VPN
VPN_PUSH_ROUTESemptyComma-separated CIDRs for split tunneling
VPN_CLIENT_TO_CLIENTfalseAllow VPN clients to reach each other
VPN_ENABLE_NATtrueMasquerade VPN traffic leaving the container
VPN_KEY_SIZE3072RSA key size for newly generated certificates
VPN_CERT_DAYS3650Server/client certificate lifetime
VPN_CA_DAYS3650CA certificate lifetime
VPN_CA_NAMEOpenVPN-CACA certificate common name
OPENVPN_IMAGEghcr.io/holms/docker-openvpn:latestImage reference to run
OPENVPN_DOCKERFILEDockerfileLocal build variant: Dockerfile or Dockerfile.debian
ALPINE_VERSION3.24Alpine base for local Alpine builds
DEBIAN_VERSION13-slimDebian 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
⁠IPv6 leak protection

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.

⁠Updating

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.

⁠Local image builds

Alpine is the default local build:

./vpnctl up --build

Debian local build:

OPENVPN_DOCKERFILE=Dockerfile.debian

Then run:

./vpnctl up --build

⁠Networking and firewall

The container:

  1. publishes VPN_PORT/VPN_PROTO on the host,
  2. enables IPv4 forwarding in its container namespace,
  3. creates nftables NAT/forwarding rules for VPN_SUBNET, and
  4. falls back to iptables compatibility backends when nftables is unavailable.

This does not open the external firewall or cloud security-group port for you. For the default configuration, allow inbound UDP 1194 to the host.

⁠Troubleshooting

Run diagnostics first:

./vpnctl doctor
./vpnctl logs
SymptomLikely cause and fix
/dev/net/tun is not availableRun sudo modprobe tun on the host, or enable TUN/TAP in the VPS control panel
Clients time outCheck public DNS/IP, host firewall, cloud security group, and router forwarding
UDP port is open but TCP was testedUDP and TCP firewall rules are different; test/open the correct protocol
Clients connect without internetCheck VPN_SUBNET overlap, VPN_ENABLE_NAT, and NAT errors in logs
Config changes have no effectRecreate with ./vpnctl up and export new client profiles
Rootless container cannot startRootless runtimes may block TUN or nftables; use normal rootful Docker on Linux
Old client cannot connectUse an OpenVPN 2.5+ client with tls-crypt-v2 support

⁠Security notes

  • Client .ovpn files contain private keys. Treat them as secrets.
  • The Docker volume contains the CA and all private keys. Protect the host, volume, and backups.
  • Automatic bootstrap uses passphrase-less keys so the server can start without interaction. Do not use this model if you require an offline CA.
  • Compression is disabled. Legacy BF-CBC fallback is intentionally unsupported.
  • Revocation updates the CRL used for new connections.

⁠Backup and reset

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.

⁠Maintainer releases

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.

Tag summary
Recent tags
Content type
Image
Digest
sha256:120e758e4…
Size
12.6 MB
Last updated
4 days ago
docker pull holms/docker-openvpn:latest