JSON 형식으로 Docker Desktop 상태 확인
이전 단계에서는 docker info의 기본 출력 형식을 사용하여 Docker 데몬 상태를 확인했습니다. 기본 형식은 사람이 읽기 쉽지만 프로그래밍 방식으로 처리하는 데는 적합하지 않습니다. 이 단계에서는 스크립팅 및 자동화에 훨씬 더 적합한 JSON 형식으로 Docker 정보를 얻는 방법을 배우겠습니다.
JSON 형식으로 출력을 얻으려면 docker info 명령과 함께 --format 플래그를 사용하고 형식을 json으로 지정할 수 있습니다.
터미널에서 다음 명령을 실행합니다.
docker info --format '{{json .}}'
이 명령을 자세히 살펴보겠습니다.
docker info: Docker 시스템 정보를 얻기 위한 기본 명령입니다.
--format '{{json .}}': 이 플래그는 Docker 에 출력을 형식화하도록 지시합니다. 값 '{{json .}}'은 Go 템플릿 구문을 사용합니다. .은 docker info에서 반환된 전체 데이터 구조를 나타내고, {{json .}}은 이 구조를 JSON 문자열로 형식화합니다.
명령을 실행하면 이전과 동일한 정보가 표시되지만 이번에는 단일 유효한 JSON 객체로 표시됩니다. 출력은 다음과 유사하게 보입니다 (정확한 내용은 Docker 환경에 따라 다릅니다).
{
"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
}
이 JSON 출력은 스크립팅 언어 또는 기타 도구로 쉽게 구문 분석할 수 있으므로 Docker 와 관련된 작업을 자동화하는 데 매우 유용합니다.