Set up VPN server with Docker in 5 mins on Azure

In this post, I’ll set up and run a temporary VPN server using docker on the Azure, it’s an L2TP type VPN, I’m not gonna recommend using this type VPN for your production environment or at work as it is unsafe.

Info:
CentOS: 7.5 x64
Docker: 19.03.5

Install Docker

Set up the repository

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

install docker-community

$ sudo yum install docker-ce docker-ce-cli containerd.io

start docker & Check docker version

$ sudo systemctl start docker
$ sudo docker version

pull VPN image from Docker Hub

$sudo docker pull fcojean/l2tp-ipsec-vpn-server

declare secret, username and password in vpn.env file.

VPN_IPSEC_PSK=Marvel
VPN_USER=avengers
VPN_PASSWORD=assemble

if you have multiple users, you can declare variables in your vpn.env file.

VPN_ADDL_USERS=additional_username_1 additional_username_2
VPN_ADDL_PASSWORDS=additional_password_1 additional_password_2

Start VPN server

$ docker run \
    --name ipsec-vpn-server \
    --env-file ./vpn.env \
    --restart=always \
    -p 500:500/udp \
    -p 4500:4500/udp \
    -d --privileged \
    hwdsl2/ipsec-vpn-server

check VPN status

$ docker exec -it ipsec-vpn-server ipsec status

Allow inbound security rules on Azure
add a new rule to allow port 1701/500/4500 to communicate.