Introduction
In this lab, you will learn how to list Docker Desktop modules using the docker version command. We will explore different ways to view this information, including listing all modules, displaying the output in JSON format, and extracting only the module IDs. This hands-on exercise will help you understand the components of your Docker installation and how to retrieve information about them.
List all Docker Desktop modules
In this step, we will learn how to list all the Docker Desktop modules using the docker version command. The docker version command provides detailed information about the Docker installation, including the client and server components, and the modules that are part of the Docker Desktop installation.
To list all the Docker Desktop modules, open your terminal and run the following command:
docker version
This command will output a lot of information about your Docker installation. Look for sections like Client and Server. Within these sections, you will find details about various components and modules.
For example, the output might look something like this (the exact output may vary depending on your Docker version and installation):
Client: Docker Engine - Community
Version: 20.10.21
API version: 1.41
Go version: go1.16.15
Git commit: f2213a1
Built: Thu Oct 27 00:18:36 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.21
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 3056e8c
Built: Thu Oct 27 00:17:23 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd358bba7fd9c7bb19904ba6d2f58fd60b1ca2b
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
In this output, you can see information about the Docker Engine, containerd, runc, and docker-init. These are some of the key modules that make up the Docker environment. The docker version command is a useful tool for understanding the different components of your Docker installation and their versions.
List Docker Desktop modules in JSON format
In the previous step, we used the docker version command to list the Docker Desktop modules. The default output is human-readable, but sometimes you might need the output in a structured format, like JSON, for scripting or further processing.
The docker version command supports a --format flag that allows you to specify the output format using Go's text/template package. To get the output in JSON format, you can use the json . template.
Run the following command in your terminal:
docker version --format '{{json .}}'
This command will output the same information as docker version, but formatted as a JSON object. The {{json .}} part is the template that tells Docker to format the entire output (.) as JSON.
The output will be a single line of JSON data, which might look something like this (formatted for readability):
{
"Client": {
"Version": "20.10.21",
"ApiVersion": "1.41",
"GoVersion": "go1.16.15",
"GitCommit": "f2213a1",
"Built": "Thu Oct 27 00:18:36 2022",
"OsArch": "linux/amd64",
"Context": "default",
"Experimental": true
},
"Server": {
"Engine": {
"Version": "20.10.21",
"ApiVersion": "1.41",
"MinAPIVersion": "1.12",
"GoVersion": "go1.16.15",
"GitCommit": "3056e8c",
"Built": "Thu Oct 27 00:17:23 2022",
"OsArch": "linux/amd64",
"Experimental": false
},
"Containerd": {
"Version": "1.6.8",
"GitCommit": "9cd358bba7fd9c7bb19904ba6d2f58fd60b1ca2b"
},
"Runc": {
"Version": "1.1.4",
"GitCommit": "v1.1.4-0-g5fd4c4d"
},
"DockerInit": {
"Version": "0.19.0",
"GitCommit": "de40ad0"
}
}
}
This JSON output contains the same information as the default output, but in a structured format that is easy for programs to parse. This is particularly useful when you want to extract specific pieces of information from the docker version output in scripts.
List only the IDs of Docker Desktop modules
In the previous steps, we learned how to list all Docker Desktop modules and how to format the output as JSON. Now, let's explore how to extract only specific information, such as the Git commit IDs of the modules. This is useful when you only need a particular piece of data for scripting or automation.
We can again use the --format flag with a custom template to achieve this. By inspecting the JSON output from the previous step, we can see that the Git commit IDs are located under Server.Engine.GitCommit, Server.Containerd.GitCommit, Server.Runc.GitCommit, and Server.DockerInit.GitCommit.
We can construct a template to extract these specific fields. Run the following command in your terminal:
docker version --format 'Engine GitCommit: {{.Server.Engine.GitCommit}}\nContainerd GitCommit: {{.Server.Containerd.GitCommit}}\nRunc GitCommit: {{.Server.Runc.GitCommit}}\nDockerInit GitCommit: {{.Server.DockerInit.GitCommit}}'
Let's break down the template:
Engine GitCommit: {{.Server.Engine.GitCommit}}: This part extracts theGitCommitvalue from theEngineobject within theServerobject.\n: This adds a newline character to separate the output for each module.Containerd GitCommit: {{.Server.Containerd.GitCommit}}: Extracts theGitCommitfor containerd.Runc GitCommit: {{.Server.Runc.GitCommit}}: Extracts theGitCommitfor runc.DockerInit GitCommit: {{.Server.DockerInit.GitCommit}}: Extracts theGitCommitfor docker-init.
The output will show the Git commit ID for each specified module, similar to this:
Engine GitCommit: 3056e8c
Containerd GitCommit: 9cd358bba7fd9c7bb19904ba6d2f58fd60b1ca2b
Runc GitCommit: v1.1.4-0-g5fd4c4d
DockerInit GitCommit: de40ad0
This demonstrates the power of the --format flag and Go templates for extracting specific data from Docker commands. You can customize the template to extract any field available in the docker version output.
Summary
In this lab, we learned how to list Docker Desktop modules using the docker version command. We explored how to display all modules and their details, which provides valuable information about the different components of the Docker installation, such as the Docker Engine, containerd, runc, and docker-init, along with their versions.
We also learned how to list Docker Desktop modules in JSON format, which is useful for programmatic processing and integration with other tools. Finally, we covered how to list only the IDs of the Docker Desktop modules, providing a concise output for quick identification.



