DEV Community

Cover image for How to Create Docker Images in Windows without Docker Desktop using WSL2
Federico Navarrete
Federico Navarrete

Posted on • Updated on • Originally published at supernovaic.blogspot.com

How to Create Docker Images in Windows without Docker Desktop using WSL2

Most people are aware that Docker Desktop is not available anymore for Windows users for free, and this became a challenge. For a couple of months, I thought if there was an alternative for my team, and I came up with a solution using WSL2 and Ubuntu.

To get started you must complete two requirements:

1) Install Windows Subsystem for Linux 2 (it doesn't work with WSL1):

Install WSL | Microsoft Docs

2) Download Ubuntu from the Microsoft Store:

Get Ubuntu - Microsoft Store

After you have installed Ubuntu and opened it for the first time, you can check in PowerShell to see if the version is correct with this command:

wsl -l -v

And you must get something like this:

preview

If it's incorrect, you can check this tutorial and upgrade your Kernel to version 2:

Manual installation steps for older versions of WSL | Microsoft Docs

And later run this command:

wsl --set version Ubuntu 2

After everything is ready, you must run the following scripts in Ubuntu:

First part:

sudo apt-get update

Second part:



sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null


Enter fullscreen mode Exit fullscreen mode

Third part:



sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

sudo apt-get install docker-compose


Enter fullscreen mode Exit fullscreen mode

Fourth part:

Run this line to start your Docker every time you need it.

sudo dockerd

dockerd preview

And that's all! Just open a new Ubuntu window and start playing with Docker!

NOTE:

If you have any issue with the network, check the following location and edit its nameserver IP to 8.8.8.8:

sudo nano /etc/resolv.conf

network

And to prevent the file is overwritten every time, you can modify this location:

sudo nano /etc/wsl.conf

And add these lines:

[network]
generateResolvConf = false

UPDATE:

You can also call the Docker commands from WSL using: wsl docker ...

Follow me on:

Personal LinkedIn YouTube Instagram Cyber Prophets Sharing Your Stories
Personal LinkedIn YouTube Instagram RedCircle Podcast RedCircle Podcast

sponsor me

Top comments (0)