-apt-get install -y linux-image-4.15.0-45-lowlatency curl jq netcat docker.io=${DOCKERVERSION}
-apt-get install -y kubernetes-cni=${CNIVERSION}
-apt-get install -y --allow-unauthenticated kubeadm=${KUBEVERSION} kubelet=${KUBEVERSION} kubectl=${KUBEVERSION}
+RES=$(apt-get install -y virt-what curl jq netcat 2>&1)
+if [[ $RES == */var/lib/dpkg/lock* ]]; then
+ echo "Fail to get dpkg lock. Wait for any other package installation"
+ echo "process to finish, then rerun this script"
+ exit -1
+fi
+
+if ! echo $(virt-what) | grep "virtualbox"; then
+ # this version of low latency kernel causes virtualbox VM to hang.
+ # install if identifying the VM not being a virtualbox VM.
+ apt-get install -y linux-image-4.15.0-45-lowlatency
+fi
+
+
+if [ -z ${DOCKERVERSION} ]; then
+ apt-get install -y --allow-change-held-packages --allow-unauthenticated --ignore-hold docker.io
+else
+ apt-get install -y --allow-change-held-packages --allow-unauthenticated --ignore-hold docker.io=${DOCKERVERSION}
+fi
+systemctl enable docker.service
+
+if [ -z ${CNIVERSION} ]; then
+ apt-get install -y --allow-change-held-packages --allow-unauthenticated --ignore-hold kubernetes-cni
+else
+ apt-get install -y --allow-change-held-packages --allow-unauthenticated --ignore-hold kubernetes-cni=${CNIVERSION}
+fi
+
+if [ -z ${KUBEVERSION} ]; then
+ apt-get install -y --allow-change-held-packages --allow-unauthenticated --ignore-hold kubeadm kubelet kubectl
+else
+ apt-get install -y --allow-change-held-packages --allow-unauthenticated --ignore-hold kubeadm=${KUBEVERSION} kubelet=${KUBEVERSION} kubectl=${KUBEVERSION}
+fi
+