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.
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.
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
When the computer has restarted, a window like the following will open:
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.
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.
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:
sudo apt update && sudo apt upgrade
This action will request the password that we assigned to our user.
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.
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.
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.
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:
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:
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
.
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:
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:
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:
Don't forget to run the following command and then run the Docker hello-world again:
newgrp docker
Now if everything went well, you should get an image like the following when running the Docker hello-world:
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:
wsl docker --version
wsl docker-compose --version
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:
echo $PROFILE
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:
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:
docker --version
docker ps
docker-compose --version
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 (Community Edition) 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 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
- Using Docker and Kubernetes without Docker Desktop on Windows 11
- How to run docker on Windows without Docker Desktop
- How to install Linux on Windows with WSL
- Install Docker Engine on Ubuntu
- Install Lazydocker on Ubuntu 22.04
- How to Install Portainer 2.0 on your Docker
Top comments (1)
Thanks for these instructions! They have worked really well until I got this message:
"Microsoft.PowerShell_profile.ps1 is not digitally signed. You cannot run this script on the current system."
How would you resolve this issue?