OpenVPN Server in a Docker Container with EasyRSA PKI CA. Based on kylemanna/openvpn.
6.9K
Originally based on https://github.com/kylemanna/docker-openvpn
OpenVPN server in a Docker container complete with an EasyRSA PKI CA.
https://hub.docker.com/r/blcarlson01/openvpn
docker build -t openvpn:latest .
Pick a name for the $OVPN_DATA data volume container. It's recommended to
use the ovpn-data- prefix to operate seamlessly with the reference systemd
service. Users are encourage to replace example with a descriptive name of
their choosing. i.e. OVPN_DATA="openvpn-data"
OVPN_DATA="ovpn-data-example"
Initialize the $OVPN_DATA container that will hold the configuration files
and certificates. The container will prompt for a passphrase to protect the
private key used by the newly generated certificate authority.
docker volume create --name $OVPN_DATA
This is an area that I changed from the original instructions.
docker run -v $OVPN_DATA:/etc/openvpn --rm openvpn:latest ovpn_genconfig -u udp://VPN.SERVERNAME.COM -C 'AES-256-CBC' -a 'SHA384'
docker run -e EASYRSA_KEY_SIZE=4096 -v $OVPN_DATA:/etc/openvpn --rm -it openvpn:latest ovpn_initpki
docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN openvpn:latest
I also modified these instructions. Replace CLIENTNAME with what you want the user to be called.
docker run -e EASYRSA_KEY_SIZE=4096 -v $OVPN_DATA:/etc/openvpn --log-driver=none --rm -it openvpn:latest easyrsa build-client-full CLIENTNAME nopass
Replace CLIENTNAME with what you want the user to be called.
docker run -v $OVPN_DATA:/etc/openvpn --log-driver=none --rm openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
docker run --rm -it -v $OVPN_DATA:/etc/openvpn --rm openvpn:latest ovpn_listclients
See Security Details for additional processes to run within and on the host environment and Dockerfile.
Backs up your configuration.
docker run -v $OVPN_DATA:/etc/openvpn --rm openvpn tar -cvf - -C /etc openvpn | xz > openvpn-backup.tar.xz
Create an volume container named $OVPN_DATA and extract the data to it.
docker volume create --name $OVPN_DATA
xzcat openvpn-backup.tar.xz | docker run -v $OVPN_DATA:/etc/openvpn -i blcarlson01/openvpn tar -xvf - -C /etc
The systemd service aims to make the update and invocation of the docker-openvpn container seamless. It automatically downloads the latest docker-openvpn image and instantiates a Docker container with that image. At shutdown it cleans-up the old container. For more details and setup see systemd Service Setup.
Minor modification from the original documentation and scripts.
docker run -v $OVPN_DATA:/etc/openvpn -p 1194:1194/udp --privileged -e DEBUG=1 openvpn
Test using a client that has openvpn installed correctly
$ openvpn --config CLIENTNAME.ovpn
Run through a barrage of debugging checks on the client if things don't just work
$ ping 8.8.8.8 # checks connectivity without touching name resolution
$ dig google.com # won't use the search directives in resolv.conf
$ nslookup google.com # will use search
Consider setting up a systemd service for automatic start-up at boot time and restart in the event the OpenVPN daemon or Docker crashes.
Copy/Paste from https://github.com/kylemanna/docker-openvpn
Content type
Image
Digest
Size
57 MB
Last updated
about 5 years ago
docker pull blcarlson01/openvpn