Most of the time, we need a Linux-only environment for development and have to work without a Macbook or an Ubuntu laptop. In the following paragraphs, we will build and debug dotnet microservices that can be deployed to the docker engine running on WSL2.
Run these commands from PowerShell to enable WSL and Virtual Machine windows features and then restart the machine
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Install WSL and upgrade to WSL 2
wsl --install
Download WSL2 kernel Upgrade https://aka.ms/wsl2kernel and run the setup. Run these commands in PowerShell.
wsl -l -v
wsl --set-version Ubuntu-20.04 2
https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701?hl=en-us&gl=us
Start windows terminal. Click the + icon to start the Ubuntu terminal.
Source: https://learn.microsoft.com/en-us/windows/wsl/install
Download and install the latest Ubuntu release.
https://apps.microsoft.com/store/detail/ubuntu/9PDXGNCFSCZV?hl=en-us&gl=us
Run these commands in the terminal to install docker-engine.
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install \
   ca-certificates \
   curl \
   gnupg \
   lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
 $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo usermod -aG docker $USER
sudo service docker start
sudo service docker status
docker ps
"Cannot connect to the Docker daemon. Is the docker daemon running on this host?" Error
Commands to fix the above-mentioned error
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
sudo service docker start
sudo service docker status
docker ps
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
Source: https://docs.docker.com/engine/install/ubuntu/
docker run -d -p 9000:9000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
Go to http://localhost:9000 to set up the portainer username and password
Source: https://docs.portainer.io/