Serengeti logo BLACK white bg w slogan

Docker With WSL2

Abhijeet Koli, Lead Software Developer

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 and run the setup. Run these commands in PowerShell.

wsl -l -v

wsl --set-version Ubuntu-20.04 2

Install Windows Terminal

Start windows terminal. Click the + icon to start the Ubuntu terminal.


Install Ubuntu on WSL2

Download and install the latest Ubuntu release.

Install Docker Engine

Run these commands in the terminal to install docker-engine.

sudo apt-get remove docker docker-engine containerd runc

sudo apt-get update

sudo apt-get install \

    ca-certificates \

    curl \

    gnupg \


sudo mkdir -p /etc/apt/keyrings

curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \

  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \

  $(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 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 "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

docker-compose --version


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


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.