Manage and monitor your containers with Docker CLI tools
A command center for container management
The Docker command-line interface (Docker CLI) is a robust tool that empowers you to interact with Docker containers and manage different aspects of the container ecosystem directly from the command line. With the CLI, you can efficiently handle tasks such as creating, starting, stopping, and deleting containers, as well as managing container images, networks, and volumes. The Docker CLI provides a powerful and flexible option for managing containers and their resources.
Why use the CLI?
Accelerated control
The Docker CLI provides users with a convenient way to quickly manage containers from any terminal. The CLI lets you build images, manage images on Docker Hub, start and stop containers, and monitor container status from the command line. This powerful tool streamlines container management by providing a comprehensive set of commands that can be easily executed from a single interface.
Scriptability
The Docker CLI’s scriptability allows users to automate container management tasks, such as building, deploying, scaling containers, and scheduling tasks with cron. The Docker CLI’s scriptability also makes it easy to integrate with other automation tools and systems, enhancing its flexibility and utility for container management.
Headless operation
The Docker’s CLI allows for full control of the container environment, even when in a headless environment.
Manage Docker where you code
Manage your Docker containers directly from your code editor or IDE.
Docker CLI third-party add-ons
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Enter fullscreen mode
Exit fullscreen mode
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
Docker CLI for Windows
Get docker cli
At the moment the docker cli to download is a beta version
You can download it from releases page https://github.com/mars-86/docker-cli/releases
Overview
Use docker on windows from command line.
Installation
Prerequisites
Windows subsystem for linux
- turn windows features on or off
- enable windows subsystem for linux
- enable virtual machine platform
- wsl —update
- wsl —set-default-version 2
Mingw
You will need to install mingw if you download the docker-cli version without libraries.
Install docker CLI
Just run install.bat and it will install docker cli on user’s root folder
Usage
Run docker command from console.
Building for source
- Install mingw https://www.mingw-w64.org/
- Add bin folder to path
- Clone the repository
- Run compile.bat
It should generate a bin folder with an executable file inside every module and install.bat on root folder
⚠️ Antivirus
You may have problems due to antivirus, specifically McAfee.
Troubleshooting
- The operation could not be started because a required feature is not installed.
-> enable virtual machine platform (https://github.com/mars-86/docker-cli/tree/main#prerequisites). - Daemon does not starts on init or stops unexpectedly
-> go to %USERPROFILE%\docker-cli\daemon\ and run dockerd.exe manually. - WSL stops instances after windows sleeps (microsoft/WSL#8763)
-> go to edit plan settings and change all the options in «choose what the power buttons do» to hibernate,
also go to «change when the computer sleeps» and set the options under «put the computer to sleep» to never.
License
MIT
Docker CLI & Docker Engine for Windows containers. Docker is an open platform for developing, shipping, and running applications.
Command Line
Download Links For Version 26.1.1
Download Links For Version 24.0.7
Download Links For Version 24.0.5
Download Links For Version 24.0.2
Download Links For Version 26.1.2
Download Links For Version 26.1.3
Download Links For Version 26.1.4
Download Links For Version 27.0.1
Download Links For Version 27.0.2
Download Links For Version 27.0.3
Download Links For Version 27.1.0
Download Links For Version 27.1.1
Download Links For Version 27.2.0
Download Links For Version 27.2.1
Download Links For Version 27.3.0
Download Links For Version 27.3.1
Download Links For Version 27.4.0
Download Links For Version 27.4.1
Download Links For Version 27.5.0
Download Links For Version 27.5.1
Download Links For Version 28.0.0
Download Links For Version 28.0.1
Download Links For Version 28.0.2
Download Links For Version 28.0.3
Download Links For Version 28.0.4
Download Links For Version 28.1.0
Download Links For Version 28.1.1
Info
last updated 4/30/2024 12:00:00 AM
Publisher:
Docker Inc.
License:
Apache-2.0
Dependencies
No dependency information
Share
Today, I am happy to announce that you can now use a Docker client directly from your Windows machine to manage containers running on Linux hosts.
In the last several weeks after Microsoft’s partnership with Docker announcement, we have added several features to make it easy to integrate Docker containers with Microsoft Azure including Portal support for Azure extensions to setup a Docker host on Azure Linux VMs and support for private registry on Azure – see Ahmet Alp Balkan’s blog on How to Deploy a Private Docker Registry on Azure.
Today, I am happy to announce that you can now use a Docker client directly from your Windows machine to manage containers running on Linux hosts. For more details on how to build and setup up a Docker CLI – Command Line Interface for Windows, reference: How to compile Docker on Windows. Up till today you could only use Linux based client CLI to manage your Docker container deployments or use boot2docker to set up a virtualized development environment in a Windows client machine. Today, with a Windows CLI you can manage your Docker hosts wherever they are directly from your Windows Clients.
The code for Docker client is integrated into the official Docker GitHub repository and you can follow its active development under Pull Request#9113.
As a bonus, this week, following Microsoft’s announcement of open sourcing .NET core framework and Linux distribution, we have made available a Docker image for ASP.NET on Docker Hub which you can take advantage of to create ASP.NET ready containers from the base image. You can access the ASP.NET image from Docker Hub directly at: https://registry.hub.docker.com/u/microsoft/aspnet/