Configuring Docker without Docker Desktop on Windows / WSL2
Tags: docker, wsl, wsl2, ubuntu
Published: 2022-02-13 14:24:08

Hello,

Since February 1st, 2022 **Docker Desktop** is not free anymore for companies that have more than 250 employees or more than $10 million in annual revenue: [Docker FAQs](https://www.docker.com/pricing/faq).

But, as stated in the above link, it is still possible to use only Docker CLI and Engine for free: 

_Can I just install the Docker CLI instead of using Docker Desktop?_

_If you use a Mac, you can install Docker CLI and Engine inside a virtual machine, using VirtualBox or VMware Fusion for example, which may require purchasing a license for VirtualBox or VMware Fusion. On Windows you could install and run Docker CLI and Engine inside WSL2. If you use a Linux machine you can easily use the Docker CLI and Docker Engine, See the documentation on installing Docker Engine for instructions. Docker Desktop is not yet available for Linux._

This post purpose is provide a step-by-step to still run Docker commands on **Windows** via **WSL2**, after uninstalling Docker Desktop. For that, we're going to use the **Ubuntu** distribution.

So we're going to:

1. Uninstall Docker Desktop on Windows
2. Configure WSL2 on Windows
3. Install Ubuntu on Windows
4. Install Docker CLI + Compose on Ubuntu
5. Execute Docker commands.

# About WSL and WSL2

**WSL (Windows Sybsystem for Linux)** allows you to run Linux command-line tools and apps alongside your Windows command-line, desktop and store apps, and to access your Windows files from within Linux. This enables you to use Windows apps and Linux command-line tools on the same set of files if you wish.

WSL2 is a new version of the WSL architecture that powers it to run ELF64 Linux binaries on Windows. Its primary goals are to increase file system performance, as well as adding full system call compatibility.

# Uninstalling Docker Desktop on Windows

If installed, uninstall Docker Desktop on Windows via Control Panel - Programs and Features - Uninstall.

That will make docker commands stop working on Windows.

# Enabling WSL on Windows

In order to enable WSL on Windows, execute the following commands in **PowerShell** running in **admin mode**:

```
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
```

Open PowerShell again and run the wsl command. If it does not work, restart your PC.

# Configuring WSL2

Download the WSL2 kernel via: [https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi](https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi)

Execute the downloaded **wsl_update_x64.msi** file.

WSL version 1 is the default, it's important to change to version 2, so all Linux installed distros will be v2 by default. 

In order to do that, execute the following command in **PowerShell** running in **admin mode**:

```
wsl --set-default-version 2
```

# Limiting WSL2 resources (optional)

If you want to limit WSL2 resources, create a file named **.wslconfig** in you user root folder on Windows (C:\Users\<your_username>) and define the configurations, e.g.:

```
[wsl2]
memory=8GB
processors=4
swap=2GB
```

# Installing Ubuntu on Windows

In the **Windows Store** app, choose the **Ubuntu** Linux distribution and download/install it. 

After that, your **WSL2 / Ubuntu** is already working. 

You can enter the **Ubuntu** terminal from the Windows start menu. 

The first time Ubuntu is run, it's necessary to define an username. Uou can use the same Windows username and password. This will be the **root ** user of you WSL2 instance.

## Updating Ubuntu:

**Important: All commands from this point on are performed in the Ubuntu terminal.**

```
$ sudo apt-get update

$ sudo apt-get upgrade -y
```

# Installing Docker Engine

Run the following commands in order to install the Docker Engine on the WSL2 Ubuntu instance:

```
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
$ sudo apt install apt-transport-https ca-certificates curl net-tools software-properties-common -y
$ sudo apt-get update
$ apt-cache policy docker-ce
$ sudo apt install docker-ce -y

$ sudo usermod -aG docker <incluir aqui o seu usuário do Ubuntu>

$ sudo service docker start

$ service docker status
```

# Installing Docker Compose

```
$ 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
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

$ docker-compose --version
```

# Executing Docker on Ubuntu

From now on, you may execute docker and/or docker-compose commands at will via the Ubuntu terminal. 

So suppose you were used to go to the Windows directory "C:\my-project" and run docker commands from there; now via the Ubuntu terminal, you still can go to any Windows directory, which are mounted under the /mnt directory, and run the docker commands. 

E.g. in this case:

```
$ cd /mnt/c/my-project

$ docker ....

$ docker-compose ....
```

# Installing other tools and dependencies

Depending on your use case, you may need to install other tools and dependencies on the WSL2 Ubuntu instance.

## Installing Node.js and NPM (optional)

As it is very common, this section covers the Node.js / NPM installation on Ubuntu:

```
$ sudo apt install nodejs
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
$ sudo apt -y install nodejs

$ node -v

$ sudo apt install npm

$ sudo npm cache clean -f
$ sudo npm install -g n
$ sudo n stable
$ sudo npm install -g npm@latest

$ npm -v
```

# ---

That's it! Thanks for reading.

**Adriano Sastre Vieira**.