Created
January 26, 2018 12:31
-
-
Save sudo-bmitch/a46b65bdf08f44b34d6a53122af3a75a to your computer and use it in GitHub Desktop.
Lookup Keys for Formatted Output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# docker info is great for users to read, but takes work to parse in a script | |
$ docker info | |
Containers: 9 | |
Running: 4 | |
Paused: 0 | |
Stopped: 5 | |
... | |
Swarm: active | |
NodeID: xxx | |
Is Manager: true | |
ClusterID: xxx | |
Managers: 1 | |
Nodes: 1 | |
Orchestration: | |
Task History Retention Limit: 5 | |
Raft: | |
Snapshot Interval: 10000 | |
Number of Old Snapshots to Retain: 0 | |
Heartbeat Tick: 1 | |
Election Tick: 3 | |
Dispatcher: | |
Heartbeat Period: 5 seconds | |
CA Configuration: | |
Expiry Duration: 3 months | |
Force Rotate: 4 | |
Autolock Managers: false | |
Root Rotation In Progress: false | |
Node Address: 192.168.1.1 | |
Manager Addresses: | |
xxx:2377 | |
# First, format everything as json, and pipe through jq to make it user readable | |
$ docker info -f '{{ json . }}' | jq . | |
{ | |
"ID": "xxx", | |
"Containers": 9, | |
"ContainersRunning": 4, | |
"ContainersPaused": 0, | |
"ContainersStopped": 5, | |
"Driver": "overlay2", | |
... | |
"Swarm": { | |
"NodeID": "xxx", | |
"NodeAddr": "192.168.1.1", | |
"LocalNodeState": "active", | |
"ControlAvailable": true, | |
"Error": "", | |
"RemoteManagers": [ | |
{ | |
"NodeID": "xxxx", | |
"Addr": "192.168.1.1:2377" | |
} | |
], | |
"Nodes": 1, | |
"Managers": 1, | |
"Cluster": { | |
"ID": "xxx", | |
"Version": { | |
"Index": 6270 | |
}, | |
# Now you know the key to lookup with formatted output | |
$ docker info -f '{{ .Swarm.LocalNodeState }}' | |
active | |
# For arrays, use index | |
$ docker info -f '{{ (index .Swarm.RemoteManagers 0).Addr }}' | |
192.168.1.1:2377 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment