Serengeti logo BLACK white bg w slogan
Menu

Docker With WSL2

Abhijeet Koli, Lead Software Developer
24.03.2023.

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.

Install WSL 2

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

Install Windows Terminal

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

Install Ubuntu on WSL2

Download and install the latest Ubuntu release.

https://apps.microsoft.com/store/detail/ubuntu/9PDXGNCFSCZV?hl=en-us&gl=us

Install Docker Engine

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

Install docker-compose 1.29

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/

Install Portainer

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/

Let's do business

The project was co-financed by the European Union from the European Regional Development Fund. The content of the site is the sole responsibility of Serengeti ltd.
cross