How to Configure WSL for Containers
The Windows Subsystem Linux version 2 feature allows the integration of different Linux distributions to be managed in Windows through the hyper-v hypervisor. The WSL2 difference than just being merely virtual machines, this feature allows a real integration with Windows host O.S. by accesing the resources, accessing Windows API’s, allowing executing bash shells, and having full compatilibity with Windows O.S. kernel.
Requirements for WSL
-
64 Bit Windows 10.04 O.S.
-
VT-X Bios Enabled
-
Virtual Machine Platform feature enabled
-
(Additionally) Docker Requirements:
-
SLT or Second Level Adress Translation
How to Check?
There are certian methods in Windows perspective to identify the virtualisation method. Here are some aproaches:
- From Taskmgr.exe->Performance->CPU we can rapidly check for “Virtualisation Enabled”
- Using the systeminfo tool detailing, we look into “Hyper-V Requirements”
NOTE: In this particular scenario will allow installing WSL2 but Docker won’t run because SLT
- Using the coreinfo sysinternals tool, we can look into coreinfo
Configure WSL Feature
Now we will use the help of the Deployment Image Servicing and Management tool for enabling the feature in the system.
NOTE: Remember you need a valid version of Operative System and hardware requirements for using the feature.
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Upgrade to WSL2
Now that you have enable the feature let’s upgrade it to version 2 and place it as default versioning.
wsl --set-default-version 2
Enable Virtual Administration
We need to verify that this VM feature is enabled in the O.S., You have two ways to do it:
By code you can execute:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Or you can go to GUI Windows Features->Add
NOTE The WSL feature will apear on Windows Features if you have already previously installed.
NOTE: You don’t need to have Hyper-V administration enabled, but you need just the basic configurations
for WSL to work.
Verify Docker WSL2 and requirements
Harware
-
(At least) 4 GB RAM
-
CPU 2 Core
-
VT-X Bios Technology
-
SLT or Second Level Adress Translation
O.S.
- 32 - 64 Operative System (however WSL requires 64)
Install Linux distro box
Here are 2 examples to install 2 distros, I’ve selected Ubutu and Suse due these are supported to install SQL Server in them.
For Ubuntu
PS> Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing
# Using Curl method #
PS> curl.exe -L -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604
For Suse
# Ading the package to market #
PS> Add-AppxPackage .\openSUSE-Leap-15.1-x64-Build7.19.appx
# Using Curl method #
PS> curl.exe -L -o openSUSE-Leap-15.1-x64-Build7.19.appx http://download.opensuse.org/repositories/Virtualization:/WSL/openSUSE_Leap_15.1
Here you can find the market all distros you can install.
Configure WSL in Docker
Download Docker SQL Server Images
Now we will use Docker Pull command to download
images to our Docker system, finding the complete list in the SQL Server Docker Hub
Here are the images published in Docker Hub and the code related:
docker pull mcr.microsoft.com/mssql/server:2017-latest
docker pull mcr.microsoft.com/mssql/server:2019-latest
docker pull mcr.microsoft.com/mssql/server:2017-CU22-ubuntu-16.04
docker pull mcr.microsoft.com/mssql/server:2019-CU9-ubuntu-16.04
Checking your Docker Images to use
Create SQL Containers
Now we will dedicate to build our Docker run for initial containers:
Using Docker run for SQL 2017
The following container it’s an initial example for parameters:
- The bellow Docker run command shows the use of volume local share and container path location
docker run -d -p 1433:1433 --name Daltanious \
--privileged -it -e "SA_PASSWORD=Clave01*" -e "ACCEPT_EULA=Y" \
--volume /mnt/c/Users/Beralios/Desktop/SQLBackups:/mnt/share\
-e "SA_PASSWORD=Clave01*" -e "ACCEPT_EULA=Y" d04f
- The below Docker run command shows the use of mount option by creating a Shared volumen defined
docker run -d -p 1433:1433 --name Daltanious --privileged -it \
--mount type=bind,src='shared-vol',dst='/mnt/SQL' -v -e "SA_PASSWORD=Clave01*"\
-e "ACCEPT_EULA=Y" d04f
- The below Docker run command shows the use of mount parameter defining source at Windows local host path with Linux Syntax and destiny
Note that the ‘src’ and dst path notation depends if you are executing on WSL or Powershell environment.
docker volume create shared-vol
docker run -d -p 1433:1433 --name Daltanious --privileged -it -e "SA_PASSWORD=Clave01*" \
-e "ACCEPT_EULA=Y" --mount type=bind,src=/mnt/c/Users/Beralios/Desktop, dst=/mnt/SQLBackups d04f
The containers that have been created can be monitored listing them as follows:
The Images that you have pulled from the Docker Hub, can be detailed as follows:
Using Docker Build - Image
- Create a docker file and save in local environment as detailed example:
NOTE: The mount parameter and bind depends on your configuration.
#Take Image from SQL Server
#Choose bewteen
#2019-latest
#2017-latest
FROM mcr.microsoft.com/mssql/server:2017-latest
#containing personal instructions.
#COPY testfile.txt .
RUN -d -p 1433:1433 --name Daltanious --privileged -it \
--mount type=bind,src='shared-vol',dst='/mnt/SQL' -e "SA_PASSWORD=Clave01*"\
-v sqlvolume:/var/opt/mssql\
-e "ACCEPT_EULA=Y" d04f
LABEL "name"="Daltanious"
#Copying the SQL Backups
COPY mnt/c/Users/Beralios/Desktop/SQLBackups/* /mnt/SQL/
- Build your Image as follows:
docker build . - < Dockerfile
Note if you are on Powershell
Get-Content Dockerfile | docker build -
Tools and Features
- Visual Studio Code - WSL Extension (ms-vscode-remote)
Open Windows Terminal or Powershell and
-
verify the WSL box you want to set in
-
open the VSC by running the code command with remote parameter
Set WSL 2 VSCode extension, SQL Server extension
wsl -l -v
wsl -s Ubuntu-20.04
code --remote wsl+Ubuntu-20.04
You can have additional visual support by setting up
-
ms-azuretools.vscode-docker
-
ms-mssql
So you can look at things like this…
If you want to work further on your containers using WSL2 and you have an NVIDIA graphic card, you may want to check out this CUDA configuration this CUDA configuration
No hay comentarios:
Publicar un comentario