How to Create Docker Images in Windows without Docker Desktop using WSL2
Tags: docker, windows, wsl, ubuntu
Published: 2022-02-10 15:57:00

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](https://docs.microsoft.com/en-us/windows/wsl/install)

2) Download **Ubuntu** from the **Microsoft Store**:

[Get Ubuntu - Microsoft Store](https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6?activetab=pivot:overviewtab)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/44ih1vks05xqsj7cif2n.png)

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](https://docs.microsoft.com/en-us/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package)

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
```

**Third part:**

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

sudo apt-get install docker-compose
```

**Fourth part:**

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

> sudo dockerd

![dockerd preview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ujgiw0iz6fz4csy5a2q.png)
  
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbgs7n9jwp46m3fu5oeh.png)
 
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](https://raw.githubusercontent.com/FANMixco/federiconavarrete/master/img/favicons/favicon.png)](https://federiconavarrete.com)|[![LinkedIn](https://i.stack.imgur.com/idQWu.png)](https://www.linkedin.com/in/federiconavarrete)|[![YouTube](https://i.stack.imgur.com/CFPMR.png)](https://youtube.com/c/FedericoNavarrete)|[![Instagram](https://i.stack.imgur.com/PIfqY.png)](https://www.instagram.com/federico_the_consultant)|[![RedCircle Podcast](https://i.stack.imgur.com/4XICF.png)](https://redcircle.com/shows/cyber-prophets)|[![RedCircle Podcast](https://i.stack.imgur.com/4XICF.png)](https://redcircle.com/shows/sharing-your-stories)|

[![sponsor me](https://raw.githubusercontent.com/FANMixco/Xamarin-SearchBar/master/bmc-rezr5vpd.gif)](https://www.buymeacoffee.com/fanmixco)