In the previous step, we checked the Docker daemon status using the default output format of docker info
. While the default format is easy to read for humans, it's not ideal for programmatic processing. In this step, we will learn how to get the Docker information in JSON format, which is much more suitable for scripting and automation.
To get the output in JSON format, we can use the --format
flag with the docker info
command and specify the format as json
.
Execute the following command in your terminal:
docker info --format '{{json .}}'
Let's break down this command:
docker info
: This is the base command to get Docker system information.
--format '{{json .}}'
: This flag tells Docker to format the output. The value '{{json .}}'
uses Go templating syntax. .
represents the entire data structure returned by docker info
, and {{json .}}
formats this structure as a JSON string.
After executing the command, you will see the same information as before, but this time it will be presented as a single, valid JSON object. The output will look something like this (the exact content will vary based on your Docker environment):
{
"ID": "...",
"Containers": 0,
"ContainersRunning": 0,
"ContainersPaused": 0,
"ContainersStopped": 0,
"Images": 0,
"Driver": "overlay2",
"SystemStatus": null,
"Plugins": {
"Volume": ["local"],
"Network": ["bridge", "host", "ipvlan", "macvlan", "null", "overlay"],
"Authorization": null,
"Log": [
"awslogs",
"fluentd",
"gcplogs",
"gelf",
"journald",
"json-file",
"local",
"logentries",
"splunk",
"syslog"
]
},
"MemoryLimit": true,
"SwapLimit": true,
"KernelMemory": true,
"CpuCfsPeriod": true,
"CpuCfsQuota": true,
"CpuShares": true,
"CpuSet": true,
"PidsLimit": true,
"OomKillDisable": true,
"IPv4Forwarding": true,
"BridgeNfIptables": true,
"BridgeNfIp6tables": true,
"Debug": false,
"NFd": -1,
"OomScoreAdj": -1,
"Goroutines": -1,
"SystemTime": "...",
"LoggingDriver": "json-file",
"CgroupDriver": "cgroupfs",
"CgroupVersion": "1",
"NEventsListener": -1,
"KernelVersion": "...",
"OperatingSystem": "...",
"OSType": "linux",
"Architecture": "x86_64",
"IndexServerAddress": "https://index.docker.io/v1/",
"RegistryConfig": {
"AllowNondistributableArtifactsAfterDate": "2020-12-25T00:00:00Z",
"InsecureRegistryCIDRs": ["127.0.0.0/8"],
"IndexConfigs": {
"docker.io": {
"Name": "docker.io",
"Mirrors": [],
"Secure": true,
"Official": true
}
},
"Mirrors": []
},
"NCPU": -1,
"MemTotal": -1,
"GenericResources": null,
"DockerRootDir": "/var/lib/docker",
"HttpProxy": "",
"HttpsProxy": "",
"NoProxy": "",
"ExperimentalBuild": false,
"LiveRestoreEnabled": false,
"Runtimes": { "runc": { "path": "runc" } },
"DefaultRuntime": "runc",
"Swarm": {
"NodeID": "",
"LocalNodeState": "inactive",
"ControlAvailable": false,
"Error": "",
"RemoteManagers": null
},
"ContainerdCommit": { "ID": "...", "Expected": "..." },
"RuncCommit": { "ID": "...", "Expected": "..." },
"InitCommit": { "ID": "...", "Expected": "..." },
"SecurityOptions": ["apparmor", "seccomp"],
"ProductLicense": "",
"DefaultAddressPools": null,
"Warnings": null
}
This JSON output can be easily parsed by scripting languages or other tools, making it very useful for automating tasks related to Docker.