How to use docker desktop engine ls command to list available engines

DockerDockerBeginner
Practice Now

Introduction

In this lab, you will learn how to use the docker desktop engine ls command to list available Docker engines. You will begin by understanding the purpose of this command and how it interacts with the Docker daemon in a cloud VM environment.

Following the introduction, you will explore different output formats for the docker desktop engine ls command. You will learn how to list available engines using the default table format, the JSON format for structured data, and the pretty format for enhanced readability. This lab will equip you with the skills to effectively inspect and manage your Docker engines using the docker desktop CLI.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("Docker")) -.-> docker/ContainerOperationsGroup(["Container Operations"]) docker/ContainerOperationsGroup -.-> docker/ls("List Containers") subgraph Lab Skills docker/ls -.-> lab-555141{{"How to use docker desktop engine ls command to list available engines"}} end

Understand the purpose of docker desktop engine ls

In this step, we will understand the purpose of the docker desktop engine ls command. Although the LabEx environment is a cloud VM and not a desktop environment, the docker desktop commands are still available and can be used to manage Docker engines.

The docker desktop engine ls command is used to list the available Docker engines that Docker Desktop is aware of. In a typical Docker Desktop installation, this might show different engines like the default one or potentially others if you have configured them. In our LabEx VM environment, this command will interact with the Docker daemon running on the VM.

Let's execute the command to see the output. Open your terminal in the ~/project directory.

docker desktop engine ls

You should see output similar to this, indicating the default engine:

NAME    STATUS    BUILTIN
default running   true

This output tells us the name of the engine (default), its current status (running), and whether it is a built-in engine (true). Understanding this command is the first step in managing Docker engines using the docker desktop CLI.

List available engines using the default format

In the previous step, we used the docker desktop engine ls command without any specific formatting options. This command, by default, uses a standard table format to display the information about the Docker engines. This default format is usually easy to read and provides the essential details at a glance.

Let's execute the command again to see the default output format. Ensure you are in the ~/project directory in your terminal.

docker desktop engine ls

The output will look like this:

NAME    STATUS    BUILTIN
default running   true

This is the default format. It presents the data in columns with headers: NAME, STATUS, and BUILTIN. This format is suitable for quick checks and human readability. In the next steps, we will explore other formatting options that are useful for scripting or when you need the data in a different structure.

List available engines using the json format

In this step, we will learn how to list the available Docker engines in JSON format. The JSON format is particularly useful when you need to process the output programmatically, for example, in scripts or when integrating with other tools.

To get the output in JSON format, we use the --format flag with the value json.

Execute the following command in your terminal in the ~/project directory:

docker desktop engine ls --format json

The output will be a JSON array containing objects representing each Docker engine. It will look similar to this:

[
  {
    "Name": "default",
    "Status": "running",
    "Builtin": true
  }
]

As you can see, the information is structured as a JSON object within an array, with keys like "Name", "Status", and "Builtin". This format is machine-readable and can be easily parsed by various programming languages and tools.

List available engines using the pretty format

In this step, we will explore another useful formatting option for the docker desktop engine ls command: the pretty format. The pretty format allows you to customize the output using Go template syntax, giving you fine-grained control over which fields are displayed and how they are presented.

To use the pretty format, you provide the --format flag with a Go template string. For example, to display the engine name and status, you can use the template {{.Name}}\t{{.Status}}. The . refers to the current object (an engine), and .Name and .Status access the respective fields. \t is used for a tab character to separate the columns.

Let's try listing the engine name and status using the pretty format. Execute the following command in your terminal in the ~/project directory:

docker desktop engine ls --format "{{.Name}}\t{{.Status}}"

The output will show the name and status of the engine, separated by a tab:

default running

You can include headers in the pretty format as well. To add headers, you can include them in the template string. For example, to add "ENGINE NAME" and "STATUS" headers:

docker desktop engine ls --format "ENGINE NAME\tSTATUS\n{{.Name}}\t{{.Status}}"

The output will now include the headers:

ENGINE NAME	STATUS
default	running

The \n creates a newline after the header row. The pretty format is very flexible and allows you to tailor the output to your specific needs, making it useful for both human readability and simple scripting tasks where JSON might be overkill.

Summary

In this lab, we learned how to use the docker desktop engine ls command to list available Docker engines. We began by understanding the purpose of this command, which is to display information about the Docker engines known to Docker Desktop, even in a cloud VM environment like LabEx. We then practiced listing the available engines using the default output format, which presents the engine's name, status, and whether it is built-in in a clear, readable table.

We further explored the flexibility of the docker desktop engine ls command by listing available engines using the JSON format, which is useful for programmatic processing, and the pretty format, which provides a more human-friendly, formatted output. Through these steps, we gained practical experience in using different output formats to view Docker engine information.