Sunday, February 14, 2021

How to install Windows Subsystem for Linux 2 and docker on Windows 10

Required Windows 10 update 1903 or 1909 or above
(1) Use Windows Power Shell (run as Administrator) to install WSL2
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# for Windows update 2004 or later
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# for Windows update 1903 or 1909
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
# Restart Windows after enable Enable-WindowsOptionalFeature curl -o $env:userprofile\Desktop\wsl_update_x64.msi https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
msiexec.exe /I $env:userprofile\Desktop\wsl_update_x64.msi /quiet
wsl --set-default-version 2


(2) Install Ubuntu 20.04 from Windows Store

(3) Install docker (Reference : https://docs.docker.com/engine/install/ubuntu/)
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker $USER

# Test docker
sudo /etc/init.d/docker start
docker run -e MYSQL_ROOT_PASSWORD=rootpassword -e MYSQL_USER=wpuser -e MYSQL_PASSWORD=wpuserpassword -e MYSQL_DATABASE=wordpressdb --name wordpressdb -d mariadb ; sudo docker run -e WORDPRESS_DB_USER=wpuser -e WORDPRESS_DB_PASSWORD=wpuserpassword -e WORDPRESS_DB_NAME=wordpressdb -p 8080:80 --link wordpressdb:mysql --name wordpress -d wordpress
# browser test enter address http://127.0.0.1:8080/


Test (4) Install docker-compose
sudo apt install python3.8 python3-pip
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 10
sudo pip3 -v install docker-compose


(5) For example, the creation Dockerfile to build for Quantlib juypter notebook server is as below.
P.S. You need 8G RAM to build thia dockerfile using gcc

Shell script   Select all
cd $HOME mkdir -p my-quantlib cd my-quantlib # get helloworld.ipynb wget https://raw.githubusercontent.com/lballabio/dockerfiles/master/quantlib-jupyter/Hello%20world.ipynb cat >$HOME/my-quantlib/Dockerfile_ql_1.21 <<'HEREEOF' # Dockerfile_ql_1.21 # docker build -f Dockerfile_ql_1.21 -t quantlib:1.21 . # Build Quantlib libraries for amd64 ARG tag=latest FROM ubuntu:20.04 MAINTAINER Luigi Ballabio LABEL Description="Provide a building environment where the QuantLib Python jupyter-notebook" RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential wget libbz2-dev vim git ENV boost_version=1.67.0 ENV boost_dir=boost_1_67_0 # Build boost RUN echo 'Building boost ...' RUN wget https://dl.bintray.com/boostorg/release/${boost_version}/source/${boost_dir}.tar.gz \ && tar xfz ${boost_dir}.tar.gz \ && rm ${boost_dir}.tar.gz \ && cd ${boost_dir} \ && ./bootstrap.sh \ && ./b2 --without-python --prefix=/usr -j 4 link=shared runtime-link=shared install \ && cd .. && rm -rf ${boost_dir} && ldconfig # Build Quantlib C++ RUN echo 'Building Quantlib C++ ...' ENV quantlib_version=1.21 RUN wget https://dl.bintray.com/quantlib/releases/QuantLib-${quantlib_version}.tar.gz \ && tar xfz QuantLib-${quantlib_version}.tar.gz \ && rm QuantLib-${quantlib_version}.tar.gz \ && cd QuantLib-${quantlib_version} \ && ./configure --prefix=/usr --disable-static CXXFLAGS=-O3 \ && make -j 4 && make check && make install \ && make clean \ && cd .. && ldconfig # && cd .. && rm -rf QuantLib-${quantlib_version} && ldconfig # Build Quantlib-Python RUN echo 'Build Quantlib-Python ...' RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y swig python3 python3-pip python-dev libgomp1 # Build Quantlib for Python3 RUN echo 'Install Quantlib Python' ENV quantlib_swig_version=1.21 RUN wget https://dl.bintray.com/quantlib/releases/QuantLib-SWIG-${quantlib_swig_version}.tar.gz \ && tar xfz QuantLib-SWIG-${quantlib_swig_version}.tar.gz \ && rm QuantLib-SWIG-${quantlib_swig_version}.tar.gz \ && cd QuantLib-SWIG-${quantlib_swig_version} \ && ./configure CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768" PYTHON=/usr/bin/python3 \ && make -C Python && make -C Python check && make -C Python install \ && cd .. && rm -rf QuantLib-SWIG-${quantlib_swig_version} && ldconfig # Build jupyter-notebook server RUN python3 -c "print('\033[91m Building jupyter-notebook server ... \033[0m')" RUN pip3 install --no-cache-dir jupyter jupyterlab matplotlib numpy scipy pandas ipywidgets RISE RUN jupyter-nbextension install rise --py --sys-prefix RUN jupyter-nbextension install widgetsnbextension --py --sys-prefix \ && jupyter-nbextension enable widgetsnbextension --py --sys-prefix # Build Quantlib for Python2 RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y python2 \ && apt-get clean RUN wget https://bootstrap.pypa.io/2.7/get-pip.py \ && python2 get-pip.py \ && rm get-pip.py RUN wget https://dl.bintray.com/quantlib/releases/QuantLib-SWIG-${quantlib_swig_version}.tar.gz \ && tar xfz QuantLib-SWIG-${quantlib_swig_version}.tar.gz \ && rm QuantLib-SWIG-${quantlib_swig_version}.tar.gz \ && cd QuantLib-SWIG-${quantlib_swig_version} \ && ./configure CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768" \ && make -C Python && make -C Python check && make -C Python install \ && cd .. && rm -rf QuantLib-SWIG-${quantlib_swig_version} && ldconfig RUN pip2 install --no-cache-dir numpy EXPOSE 8888 RUN mkdir /notebooks VOLUME /notebooks COPY *.ipynb /notebooks/ # Starting jupyter-notebook server RUN python3 -c "print('\033[92m Starting jupyter-notebook server at port 8888 \033[0m')" CMD jupyter notebook --no-browser --allow-root --ip=0.0.0.0 --port=8888 --notebook-dir=/notebooks HEREEOF # build image docker build -f Dockerfile_ql_1.21 -t quantlib:1.21 . # run image docker run -d -p 8888:8888 --name myquantlibtesting quantlib:1.21 # list the token of the jupyter-notebook server docker container exec -it myquantlibtesting jupyter notebook list


(6) Install youtube-dl for WSL2
wget https://github.com/ytdl-org/youtube-dl/releases/download/2021.12.17/youtube-dl
sudo chmod +x youtube-dl sudo mv youtube-dl /usr/local/bin/ sudo apt install -y openssl ffmpeg
sudo apt install python-is-python3
youtube-dl -U
youtube-dl -i -f m4a https://youtu.be/e0npW4WoGmc
# use ffmpeg to resize videp https://ottverse.com/change-resolution-resize-scale-video-using-ffmpeg/ # use ffmpeg to resize image https://stackoverflow.com/questions/28806816/use-ffmpeg-to-resize-image


(7) Install X Display Server for WSL gui app
https://techcommunity.microsoft.com/t5/windows-dev-appconsult/running-wsl-gui-apps-on-windows-10/ba-p/1493242

Run wsl app batch file
https://gist.githubusercontent.com/zarinfam/eb671a82340eadb5af9026ba6e0b666b/raw/c2d0d947a488e54eeb7fdaafae5464afc778de71/wsl-app-runner.bat

vbscript to start the batch file
https://gist.github.com/zarinfam/5dbc0e10662b79468a3da9a67c107217/raw/cf4d2d3b6095cb3c42fca0df9e86e4d3b2703671/linux-gui-app-runner.vbs



To install OpenSSH Server on Windows 10 https://virtualizationreview.com/articles/2020/05/21/ssh-server-on-windows-10.aspx

To enable ssh login default to wsl ubuntu. Should use powershell with admin authority yo rmable features. https://www.hanselman.com/blog/the-easy-way-how-to-ssh-into-bash-and-wsl2-on-windows-10-from-an-external-machine

In order not to interrupt the ssh server service, should consider to disable sleep when on power adapter. And disable automatic windows update and restart.



No comments: