Virtual Private Network or VPN is a masked network connection via the internet to the end device or a network. Masking mechanism of VPN is restricting unauthorized users from eavesdropping or hacking. Also, VPN allows users to make a connection to the private or secured network with authorization and make users use the devices in the private network remotely. Setting up this VPN required time and huge steps to follow in a normal scenario. So, this article will describe how to create a VPN server with Docker easily.
To get into the VPN setup, install the needed software and tools. Let’s list the needed tools and software.
- Docker Daemon
If your machine is not installed with Docker, Get installed with Docker first. Once Docker is installed, start with configuring OpenVPN configuration with Docker. We have the popular Docker image for OpenVPN
- Share Host Volume for Configuration:
- Set Network Interface:
- Mention Group:
- Mention User ID:
- Set Host Mode:
- Set Privileged Mode:
So, The Docker command to create OpenVPN container with
linuxserver/openvpn-as will look like this
sudo docker create --name=openvpn \ -v /home/vagrant/openvpn/config:/config \ -e INTERFACE=ens3 \ -e PGID=2090 \ -e PUID=2002 \ --net=host --privileged \ linuxserver/openvpn-as
This will pull the
linuxserver/openvpn-as image from docker hub and create the container with the following output
Unable to find image 'linuxserver/openvpn-as:latest' locally latest: Pulling from linuxserver/openvpn-as 3effdd4a0dfb: Pull complete 1ef6b0cfc06f: Pull complete fdd8ef8fcaef: Pull complete 0f088c30fb6d: Pull complete eff60a8fc64e: Pull complete df66df6fcfcd: Pull complete 0f088c30fb6d: Pull complete hef60f8fc64e: Pull complete Digest: sha256:a15a743bcec24b1b1bf2b19a9a7871ca72a5237192a942321b2342a1a5717a82 Status: Downloaded newer image for linuxserver/openvpn-as:latest c0a1eb5a40b5a423cfc210f1df654acba2c0bd9395d2deaffa979c97ea975e16
So, now we can start the OpenVPN server by starting the container by passing following command
sudo docker start openvpn
Start and Configure OpenVPN
OpenVPN will start once you have passed the above command. You can access the OpenVPN from the below URL
https://<container -IP-Address >:943/admin.
This will open the Admin page after you pass default password (
Username: admin, Password: password).
As the next step, you need to configure DNS and other setting of OpenVPN. Follow the link to configure the OpenVPN initial setup.
So, now download the respective client OpenVPN application for the
For Modern software development and other networking operations, VPN is essential and important to use. But Configuring in the virtual machine or in the physical machine is high resource-consuming and difficult to configure. As always, Docker helps to provision and run pre-configured software and we have seen how to create a VPN server with Docker easily. Here in our situation, Docker helped us to create the pre-configured OpenVPN. In our upcoming article, we will see the detailed tutorial of VPN and Docker. Stay tuned and subscribe DigitalVarys for more articles and study materials on DevOps, Agile, DevSecOps and App Development.
Experienced DevSecOps Practitioner, Tech Blogger, Expertise in Designing Solutions in Public and Private Cloud. Opensource Community Contributor.