OpenVPN server in a container running with Docker Compose.
- Docker Engine with Docker Compose plugin.
- A public DNS name or IP address for the OpenVPN server.
Follow the official Docker Engine installation guide for Ubuntu.
Copy docker-compose.yml to the target server.
Edit docker-compose.yml and set VPN_HOSTNAME in the generate-config service:
VPN_HOSTNAME: vpn.example.comUpdate the other variables in docker-compose.yml if you need to change the port, protocol, DNS server, or VPN network.
Generate the OpenVPN server config. The server config files are created in ./ovpn0:
docker compose run --rm generate-config
docker compose run --rm init-pki
docker compose run --rm copy-server-filesStart the OpenVPN server:
docker compose up -d openvpnThe init-pki step is interactive because it asks for the CA password. For a fully non-interactive but less secure setup, run:
docker compose run --rm init-pki ovpn_initpki nopassGenerate a client configuration:
CLIENT_NAME=laptop0 docker compose run --rm add-clientThe generated client file is written to:
ovpn0/laptop0.ovpn