Install Docker Engine & Minikube on WSL2

Roshit Rajan
8 min readAug 28, 2022

--

All operations mentioned below were performed, tested & verified on a Windows 11 Enterprise & Windows 10 Pro OS.

With the announcement of Windows Subsystem for Linux 2 (WSL2), Microsoft started shipping a full-blown Linux kernel with Windows 10. With this, WSL2 came equipped with a plethora of goodies for Developers and WSL enthusiasts. Now that Windows 10/11 has a Linux Kernel in it, it is needless to say that it’s the right time to the shift the gear and test the best of both worlds.

With that said, now you can install Docker in WSL2 and get a taste of a Linux-based Docker development experience. In this article we are going to setup WSL2 on your Windows 11 PC, Install Docker Engine on it & we will run a Dockerized .NET Core web app.

Note:
If your Windows instance is running using the Microsoft Azure cloud, make sure you have the right virtual machine size. To be more specific, you need a Dv3 VM size. Only these sized have nested virtualization and Hyper-V containers. For example, Standard D2 v2 will not work. You need, for example, Standard D2s v3. With this option, you can run WSL 2.

Ensure Hyper-V, Virtual Machine Platform & Windows Subsystem for Linux is enabled.
Enable all features from Windows features GUI & restart your PC.
Optional:- Follow this link to enable Hyper-V.

From PowerShell:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart.

Tools to Install

  • Windows Terminal
  • VS Code
  • Ubuntu Distro 20.04 LTS
    (The below distros are supported.)
    Ubuntu 18.04 LTS
    Ubuntu 20.04 LTS
    Ubuntu 20.04.4 LTS

Install WSL2 & Ubuntu

  • The first step if you haven’t done it already is to get WSL2 installed. Would recommend setting up WSL2 by following the Microsoft guide to install WSL2 on Windows 10. After WSL2 is setup, you can install Ubuntu by running the following command from Windows Terminal or you can install from Microsoft Store from your system.
    wsl — install -d Ubuntu”
  • “Launch” Ubuntu to open the terminal and wait for a while. You will then be asked for a user name. This is optional, but in this article, we will specify “user”. Next, you will be asked for a password. Please enter your own password.
  • Download the updated Linux kernel. Click here to download “wsl_update_x64.msi”. Run the installer to install the latest kernel.
  • Execute the following command to convert your current Linux Distribution to WSL version 2.
    wsl — set-version Ubuntu-20.04 2
  • Finally, if you want to use your WSL2 as the default version then execute the command below.
    wsl — set-default-version 2
  • If you run the confirmation command again, you will see that the version is now 2. Once you see below list with version 2 showing up for Ubuntu and “Running”, we can say WSL2 build is completed !!!.
    Type command : “wsl — list — verbose
  • Now how to switch to WSL?
    Just type WSL on Windows Terminal.
  • You can also access WSL from windows filesystem by typing “\\wsl$” as shown below.
  • To logout of WSL, just type “exit”.
  • Verify WSL & Ubuntu Versions
    WSL Version
    Type Command: “uname -r”

Verify Ubuntu Version Information
Type Command: cat /etc/os-release

Install Docker Engine on WSL2

  • Start by removing any old Docker related installations as shown below.
    On Windows: uninstall Docker Desktop
    On WSL2: sudo apt remove docker docker-engine docker.io containerd runc
    If you never had one installed before, you will see an error message.
  • Update your local Linux software repository
    sudo apt-get update
  • Download Docker dependencies.
    Option # 1: sudo apt install — no-install-recommends apt-transport-https ca-certificates curl gnupg2
    Option # 2: sudo apt-get install ca-certificates curl gnupg lsb-release
    Refer: https://docs.docker.com/engine/install/ubuntu/
  • The above command might fail giving error “temporary failure resolving ‘archive.ubuntu.com’”. To resolve run below commands in sequence.
  • echo “nameserver 8.8.8.8” | sudo tee /etc/resolv.conf > /dev/null & then run sudo apt-get update && sudo apt-get upgrade & then run sudo apt install — no-install-recommends apt-transport-https ca-certificates curl gnupg2
  • source /etc/os-release
  • Add Docker APT key
    curl -fsSL https://download.docker.com/linux/${ID}/gpg | sudo apt-key add
  • Add docker apt repository
    echo “deb [arch=amd64] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable” | sudo tee /etc/apt/sources.list.d/docker.list
  • Install the latest Docker CE version
    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
  • Start Docker service
    sudo service docker start
  • Ensure docker group exists
    sudo groupadd docker
  • Add your username to docker group so you can run docker as a non-root user as referenced here. Better to exit out of WSL terminal window then restart WSL terminal window after running below command. Now you should be able to run all docker commands without sudo
    sudo usermod -aG docker $USER && newgrp docker
    Note: the above command is very important to execute “minikube start” successfully or else you might get below error.
  • Validate Docker installation
    docker run hello-world

With this you have completed the installation of Docker! You are able to run docker in WSL without Docker Desktop.

  • Check docker version
    docker — version
  • Check docker service status
    sudo service docker status
  • Check Docker container and image status
    sudo docker info
    sudo docker ps
    sudo docker images
  • Provide permissions with chmod on the above path with root user
    “sudo -i”
    chmod +x /usr/bin/docker-compose

Dockerize Your .NET Core Web app

Visual Studio 2019/ 2022 IDE
If you love working in Visual Studio IDE, but need to test your app in Linux, go to the Visual Studio Marketplace to install the extension today. If you have it already, open VS 2019 and select WSL as shown under. Validate details as shown on console. In case you get message “ASP.NET Core 5.0 is not installed …….”, install the same.

After installation, check on WSL using command “dotnet — info”

VS Code Development
Debug from VS Code installed within WSL.

  • Open a WSL terminal window (using the start menu item or by typing wsl from a command prompt / PowerShell/ Windows Terminal).
  • Navigate to a folder you’d like to open in VS Code (including, but not limited to, Windows filesystem mounts like /mnt/c)
  • Type code . in the terminal. When doing this for the first time, you should see VS Code fetching components needed to run in WSL. This should only take a short while, and is only needed once.
    Note: If this command does not work, you may need to restart your terminal or you may not have added VS Code to your path when it was installed.
  • After a moment, a new VS Code window will appear, and you’ll see a notification that VS Code is opening the folder in WSL.

Debug from VS Code installed outside WSL.

  • Install .NET SDK 2.1, 3.1 & 6.0 on WSL as they are supported on Ubuntu 20.04 as mentioned here
    sudo apt-get install dotnet-sdk-2.1
    sudo apt-get install dotnet-sdk-3.1
    sudo apt-get install dotnet-sdk-6.0
    Note:
    In case any of the above commands fail, run below commands. You should then be able to install each version of .Net Core without issues.
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-3.1
  • Verify Installed versions of SDK & Runtime on WSL
    dotnet — list-sdks
    dotnet — list-runtimes
  • Install Visual Studio Code on the Windows side (not in WSL).
  • Install the Remote Development extension pack.
  • Now create a folder on local and run command “dotnet new mvc” & “dotnet run” to test and run a .NET application.
  • Press F1, select Remote-WSL: New Window for the default distro or Remote-WSL: New Window using Distro for a specific distro. Use the File menu to open your folder. If you already have a folder open, you can also use the Remote-WSL: Reopen in WSL command. You will be prompted which distro to use. If you are in a WSL window and want to open the current input in a local window, use Remote-WSL: Reopen in Windows. In my case as the project was already created, I used option Remote-WSL: Reopen in WSL command. Once done, the local folder get mounted on WSL as shown below. “/mnt/c/<local folder path>”.
  • Setup launch.json, tasks.json & start debugging the app from VS code within WSL.

Debugging in WSL#

  • Once you’ve opened a folder in WSL, you can use VS Code’s debugger in the same way you would when running the application locally. For example, if you select a launch configuration in launch.json and start debugging (F5), the application will start on remote host and attach the debugger to it.

Debugging from VS 2019 IDE

  • Create a new .NET Core project.
  • Create WSL 2 profile with settings as shown under. remove https (secure) URL for testing.
  • Now run the app. It will launch on WSL profile

Deploy .NET App on AWS EC2 using Jenkins

https://www.digitalonus.com/deploying-asp-net-framework-application-into-aws-through-jenkins/

Install Minikube on WSL

Install as mentioned here & finally check status.

Install HELM
Using WSL 2 and Minikube is a great way to start playing around with Kubernetes clusters without the need for standing up VMs and other lab environment prerequisites

Install Jenkins on WSL

Steps:

  1. Update the Ubuntu repository to get the latest updates of all the packages available in the repository
    sudo apt update
  2. Install JDK 11
    sudo apt-get install openjdk-11-jdk
  3. To test if Java has been installed successfully, run this command
    java -version
  4. Import the GPG key of the Jenkins from its official website using the curl command
    curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null
  5. Add the repository of the Jenkins to the Ubuntu default repository
    echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
    https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
    /etc/apt/sources.list.d/jenkins.list > /dev/null
  6. Update the repository
    sudo apt update
  7. Install Jenkins
    sudo apt install jenkins -y
  8. Enable Jenkins using the systemctl command
    sudo systemctl enable Jenkins
  9. Start Jenkins
    sudo systemctl start Jenkins
  10. Check status
    sudo systemctl status Jenkins
  11. Enable the UFW service
    sudo ufw enable
  12. Enable the port 8080 using the UFW command
    sudo ufw allow 8080
  13. Reload the firewall to effect the changes
    sudo ufw reload
  14. confirm that port 8080 is open on the firewall, execute the command
    sudo ufw status
  15. When the UFW service is enabled, open the web browser and go to the following URL http://localhost:8080 to unlock the Jenkins.
  16. Get password from path mentioned in the window that will appear and start using Jenkins.
  17. Install WinSCP as mentioned here.
  18. Install Putty from here.

--

--

Roshit Rajan
Roshit Rajan

Written by Roshit Rajan

Cloud Architect & Cloud Migration Engineer.

No responses yet