How to use docker system info command to display system information

DockerDockerBeginner
Practice Now

Introduction

In this lab, you will learn how to use the docker info command to display comprehensive information about your Docker system. You will begin by executing the basic docker info command to view details about the Docker daemon, including container and image counts, storage driver, and other system-level information.

Following the basic display, you will explore how to format the output of the docker info command in different ways. Specifically, you will learn how to format the output as JSON for easier parsing and how to use a custom template to display only the specific information you need. This lab will equip you with the skills to effectively retrieve and interpret Docker system information.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("Docker")) -.-> docker/SystemManagementGroup(["System Management"]) docker/SystemManagementGroup -.-> docker/info("Display System-Wide Information") subgraph Lab Skills docker/info -.-> lab-555249{{"How to use docker system info command to display system information"}} end

Display basic Docker system information

In this step, you will learn how to display basic information about your Docker system using the docker info command. This command provides details about the Docker daemon, including the number of containers and images, storage driver, and other system-level information.

Open the terminal in the LabEx environment. You can execute the docker info command directly.

docker info

You should see output similar to this (the exact details will vary depending on your environment):

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version: v0.10.4
    Build: 8842a472b58241d32996951f172f32259cd758e5
  compose: Docker Compose (Docker Inc.)
    Version: v2.17.2
    Build: 6833407
  scan: Docker Scan (Docker Inc.)
    Version: v0.23.0
    Build: 2c50987

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.21
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9ba4b2555a59f71c4c1c1897e93a540b0c52b883
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.0-76-generic
 Operating System: Ubuntu 22.04.2 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.84GiB
 Name: labex-vm
 ID: 6111111111111111111111111111111111111111111111111111111111111111
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio weight, cpus, or mem limits set, Docker may behave unexpectedly without them.

The output provides a comprehensive overview of your Docker installation and its current state. You can see information like the Docker version, the number of running containers and images, the storage driver being used, and details about the underlying operating system and hardware.

Format docker info output as JSON

In the previous step, you saw the default output of the docker info command. This output is human-readable but can be difficult to parse programmatically. Docker provides the --format flag to customize the output format. In this step, you will learn how to format the docker info output as JSON.

The --format flag uses Go's text/template package. To output the information as JSON, you can use the . | json template.

Execute the following command in your terminal:

docker info --format '{{json .}}'

You should see the same information as before, but now formatted as a single JSON object:

{
  "Client": {
    "Context": "default",
    "DebugMode": false,
    "Plugins": {
      "buildx": {
        "Version": "v0.10.4",
        "Build": "8842a472b58241d32996951f172f32259cd758e5"
      },
      "compose": {
        "Version": "v2.17.2",
        "Build": "6833407"
      },
      "scan": {
        "Version": "v0.23.0",
        "Build": "2c50987"
      }
    }
  },
  "Server": {
    "Containers": 0,
    "ContainersRunning": 0,
    "ContainersPaused": 0,
    "ContainersStopped": 0,
    "Images": 0,
    "ServerVersion": "20.10.21",
    "StorageDriver": "overlay2",
    "LoggingDriver": "json-file",
    "CgroupDriver": "systemd",
    "CgroupVersion": "2",
    "Plugins": {
      "Volume": ["local"],
      "Network": ["bridge", "host", "ipvlan", "macvlan", "null", "overlay"],
      "Log": [
        "awslogs",
        "fluentd",
        "gcplogs",
        "gelf",
        "journald",
        "json-file",
        "local",
        "logentries",
        "splunk",
        "syslog"
      ]
    },
    "Swarm": {
      "NodeID": "",
      "LocalNodeState": "inactive",
      "ControlAvailable": false,
      "Error": null,
      "RemoteManagers": null
    },
    "Runtimes": {
      "io.containerd.runc.v2": {
        "path": "io.containerd.runc.v2"
      },
      "io.containerd.runtime.v1.linux": {
        "path": "io.containerd.runtime.v1.linux"
      },
      "runc": {
        "path": "runc"
      }
    },
    "DefaultRuntime": "runc",
    "InitBinary": "docker-init",
    "ContainerdVersion": "9ba4b2555a59f71c4c1c1897e93a540b0c52b883",
    "RuncVersion": "v1.1.4-0-g5fd4c4d",
    "InitVersion": "de40ad0",
    "SecurityOptions": ["apparmor", "seccomp", "cgroupns"],
    "KernelVersion": "5.15.0-76-generic",
    "OperatingSystem": "Ubuntu 22.04.2 LTS",
    "OSType": "linux",
    "Architecture": "x86_64",
    "NCPU": 2,
    "MemTotal": 4123631616,
    "Name": "labex-vm",
    "ID": "6111111111111111111111111111111111111111111111111111111111111111",
    "DockerRootDir": "/var/lib/docker",
    "DebugMode": false,
    "ExperimentalBuild": false,
    "InsecureRegistries": ["127.0.0.0/8"],
    "LiveRestoreEnabled": false,
    "Warnings": [
      "No blkio weight, cpus, or mem limits set, Docker may behave unexpectedly without them."
    ]
  }
}

Formatting the output as JSON is useful when you want to process the information with other tools or scripts.

Format docker info output using a custom template

In addition to formatting the output as JSON, you can use the --format flag with a custom Go template to display specific information from the docker info output. This allows you to extract only the data you are interested in.

The docker info command provides a data structure that you can access within the template. For example, to display the Docker Server Version and the total number of CPUs, you can use the template 'Server Version: {{.ServerVersion}}, CPUs: {{.NCPU}}'.

Execute the following command in your terminal:

docker info --format 'Server Version: {{.ServerVersion}}, CPUs: {{.NCPU}}'

You should see output similar to this:

Server Version: 20.10.21, CPUs: 2

In this template:

  • {{.ServerVersion}} accesses the ServerVersion field from the docker info data structure.
  • {{.NCPU}} accesses the NCPU field, which represents the number of CPUs.

You can explore the JSON output from the previous step to identify other fields you might want to include in your custom template. For instance, to display the Operating System and the Docker Root Directory, you could use the template 'OS: {{.OperatingSystem}}, Docker Root Dir: {{.DockerRootDir}}'.

Try executing this command:

docker info --format 'OS: {{.OperatingSystem}}, Docker Root Dir: {{.DockerRootDir}}'

You should see output similar to this:

OS: Ubuntu 22.04.2 LTS, Docker Root Dir: /var/lib/docker

Using custom templates gives you fine-grained control over the output of the docker info command, making it easier to integrate Docker information into scripts or reports.

Summary

In this lab, you learned how to use the docker info command to display comprehensive information about your Docker system. You started by executing the basic docker info command to view details about the Docker daemon, including container and image counts, storage driver, and other system-level information.

Furthermore, you explored how to format the output of the docker info command. You learned to output the information in JSON format for easier parsing and integration with other tools, and also how to use a custom Go template to display specific information in a tailored format. These formatting options provide flexibility in how you access and utilize Docker system details.