How to install Docker CLI on Windows without Docker Desktop and not die trying
Tags: containers, docker, tutorial, windows
Published: 2024-03-27 19:59:15

In this post, we will explore how to install and configure Docker CLI on Windows without the need for Docker Desktop. Although Docker Desktop is a convenient and popular tool for managing Docker containers in development environments, there are situations where a lighter or more specific alternative is preferred or required. Whether due to licensing restrictions, minimal resource needs, or personal preferences, installing only Docker CLI can be the ideal solution. I will guide you through the necessary steps to set up your Windows environment to use Docker CLI, leveraging the capabilities of WSL 2 (Windows Subsystem for Linux version 2) and without the overhead of Docker Desktop. This will not only provide you with more granular control over your Docker containers but will also optimize resource usage on your machine.

## Preliminary steps for installation

The following steps have been tested on Windows 10, but I assume they will work the same for Windows 11.

The first thing to do is to install WSL, and for that, open a PowerShell console and type the following command.

```bash
wsl --install
```

After the previous step, you need to restart the operating system.

> Note: As I read, the following command does the same but additionally restarts the computer when it finishes the necessary installation.

> ```bash
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
> ```

When the computer has restarted, a window like the following will open:

![Consola terminando de instalar linux](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2z6qvlbb51gkedjebkz.png)

After waiting for some time, an English message will appear, which will tell you to enter the username for your Linux user and will also ask for the password. Write down your username and password carefully because we will need them later.

![Consola solicitando nombre de usuario para la distribución linux](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0cz8vlxnnxgjizpoqi1.png)

![Consola solicitando contraseña y confirmación de la misma para nuestro usuario en linux](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4v8yq217z1hhimxpicfb.png)

Once it has finished successfully, then it's time to start installing the Docker CLI and we will be located in the console of our Linux distribution.

![Consola linux lista para empezar a trabajar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3b48np7aawtrk95clc6b.png)

> Note: It's important to keep in mind that the distribution installed by default is Ubuntu 22 at the time of writing this tutorial.

Once at this point, the first thing to do is to update the repositories and programs of the distribution with the following command:

```bash
sudo apt update && sudo apt upgrade
```

This action will request the password that we assigned to our user.

![Solicitud de contraseña para actualizar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fj09j3k22ma6aspay5h3.png)

> Note: don't forget to say yes (press Y) to confirm that you want to proceed with installing the updates.

## Adding the official Docker CLI repository

When the updates are finished, then we will run the following command to perform some necessary installations prior to Docker CLI.

```bash
sudo apt -y install apt-transport-https ca-certificates curl gnupg lsb-release
```

After that, we will run the following command to add the necessary signature for the Docker CLI repository.

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

Now it's time to add the Docker CLI repository in Ubuntu for its subsequent installation with the following command.

```bash
echo "deb [arch=$(dpkg --print-architecture) 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
```

## Installing Docker CLI

Since we now have the Docker CLI repository ready, it's time to do the required installation with the following command:

```bash
sudo apt update && sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker docker-compose
```

At this point, we now have Docker CLI installed in our WSL, let's test it with the following commands:

```
docker --version
docker-compose --version
```

We should get a response similar to the one in the following image:

![Comprobación de los comandos docker y docker-compose](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t3oety4mky1eimg1jwr6.png)

## How to run Docker without root user

Now we will create the `docker` group and add our user to that group so our user can run containers without needing to run commands as `root`.

```bash
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
```

> Note: When you try to create the docker group, you will probably get a message saying the group already exists. If that's the case, don't worry, just proceed.

Now what we need to do is start Docker and verify it's working correctly, and for that we'll use the following commands:

```bash
sudo service docker start
sudo service docker status
docker run hello-world
```

When you run the `sudo service docker status` command, you'll get something like the following image:

![sudo service docker status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8yli1dddkhjnpq6jcp3n.png)

> To exit that, press the Q key

When using the `docker run hello-world` command, you may receive a message like the one in the following image:

![Error al correr el hola mundo de Docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1cyi5vrk5ycg4o0l5flg.png)

Don't forget to run the following command and then run the Docker hello-world again:

```bash
newgrp docker
```

Now if everything went well, you should get an image like the following when running the Docker hello-world:

![Hola Mundo de Docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mxx13j3efpvnj5nardkh.png)

With everything we've done previously, it's time to make this work "natively" in Windows through PowerShell.

## Docker in the PowerShell console

Now that Docker is installed, it's time to make it work in the PowerShell console. At the moment, Docker works great but in the console of our WSL.  

When opening a PowerShell console we can use the following commands:

```bash
wsl docker --version 
wsl docker-compose --version
```

![Ejecución de comandos docker en la PowerShell](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pivkn7fic2oqluzwwkny.png)

The idea is that we can use the commands but without the wsl prefix. To do this, we need to modify the `Microsoft.PowerShell_profile.ps1` file, but to know where to create it, we should run the following command in a PowerShell console:

```bash
echo $PROFILE
```

![Ejecucuón del comando echo $PROFILE](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmqytugybeu3abne2civ.png)

As you can see in the previous image, it shows a path and if you check that path, it probably won't exist. Well, we must create those folders and the file itself. Once you've done that, you should put the following text in the file:

```text
Function Start-WslDocker {
    wsl docker $args
}

Function Start-WslDockerCompose {
    wsl docker-compose $args
}

Set-Alias -Name docker -Value Start-WslDocker

Set-Alias -Name docker-compose -Value Start-WslDockerCompose
```

With the above, don't forget to close the PowerShell consoles and reopen them so they take the changes. And with that, we should be able to run the following Docker commands normally in the PowerShell console:

```bash
docker --version
docker ps
docker-compose --version
```

![Comando de Docker en la PowerShell](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfzrupdizf8u8ug32hbk.png)

## Visual managers

If somehow you don't like managing Docker from the console, but you long for a visual manager in the style of Docker Desktop, then I have two very powerful and free solutions for both personal and business use.

![Portainer CE](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fbb8omwh5ddm163k1e59.png)

[Portainer CE (Community Edition)](https://github.com/portainer/portainer) is a lightweight service delivery platform for containerized applications that facilitates the management of Docker, Swarm, Kubernetes, and ACI environments. This is an open-source project with community support, offering a free option for both businesses and personal use.

![Lazydocker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwjapn2yuv7t6agodbf9.png)

[Lazydocker](https://github.com/jesseduffield/lazydocker) is a simple terminal UI for both docker and docker-compose, written in Go with the gocui library. Its goal is to simplify Docker management, making it more accessible and less tedious for those who prefer to work from the terminal. It provides a clear overview of Docker containers, images, and volumes, allowing users to perform common actions with just a keypress or click, making it an efficient tool for both personal and business use. As an open-source project, Lazydocker is a free option that facilitates uncomplicated Docker management, making it ideal for personal and business use.

## Final conclusions 

As you can see, the Docker CLI can be managed in Windows without the need to rely on Docker Desktop, and easily through the console.

## References

- [How To Install Docker Without Docker Desktop On Windows](https://www.paulsblog.dev/how-to-install-docker-without-docker-desktop-on-windows/)
- [Using Docker and Kubernetes without Docker Desktop on Windows 11](https://cuteprogramming.blog/2023/05/21/using-docker-and-kubernetes-without-docker-desktop-on-windows-11/)
- [How to run docker on Windows without Docker Desktop](https://dev.to/_nicolas_louis_/how-to-run-docker-on-windows-without-docker-desktop-hik)
- [How to install Linux on Windows with WSL](https://learn.microsoft.com/en-us/windows/wsl/install)
- [Install Docker Engine on Ubuntu](https://docs.docker.com/engine/install/ubuntu/)
- [Install Lazydocker on Ubuntu 22.04](https://lindevs.com/install-lazydocker-on-ubuntu)
- [How to Install Portainer 2.0 on your Docker](https://www.letscloud.io/community/how-to-install-portainer)