我正在尝试使用以下jq过滤器过滤docker-machine的输出。
docker-machine inspect default | jq '{ConfigVersion, .Driver.{MachineName, CPU, Memory}, DriverName}'
第一个命令的原始json在这里
{
"ConfigVersion": 3,
"Driver": {
"IPAddress": "192.168.99.100",
"MachineName": "default",
"SSHUser": "docker",
"SSHPort": 52314,
"SSHKeyPath": "/Users/apatil/.docker/machine/machines/default/id_rsa",
"StorePath": "/Users/apatil/.docker/machine",
"SwarmMaster": false,
"SwarmHost": "tcp://0.0.0.0:3376",
"SwarmDiscovery": "",
"VBoxManager": {},
"HostInterfaces": {},
"CPU": 2,
"Memory": 5120,
"DiskSize": 20000,
"NatNicType": "82540EM",
"Boot2DockerURL": "",
"Boot2DockerImportVM": "",
"HostDNSResolver": false,
"HostOnlyCIDR": "192.168.99.1/24",
"HostOnlyNicType": "82540EM",
"HostOnlyPromiscMode": "deny",
"UIType": "headless",
"HostOnlyNoDHCP": false,
"NoShare": false,
"DNSProxy": true,
"NoVTXCheck": false,
"ShareFolder": ""
},
"DriverName": "virtualbox",
"HostOptions": {
"Driver": "",
"Memory": 0,
"Disk": 0,
"EngineOptions": {
"ArbitraryFlags": [],
"Dns": null,
"GraphDir": "",
"Env": [],
"Ipv6": false,
"InsecureRegistry": [],
"Labels": [],
"LogLevel": "",
"StorageDriver": "",
"SelinuxEnabled": false,
"TlsVerify": true,
"RegistryMirror": [],
"InstallURL": "https://get.docker.com"
},
"SwarmOptions": {
"IsSwarm": false,
"Address": "",
"Discovery": "",
"Agent": false,
"Master": false,
"Host": "tcp://0.0.0.0:3376",
"Image": "swarm:latest",
"Strategy": "spread",
"Heartbeat": 0,
"Overcommit": 0,
"ArbitraryFlags": [],
"ArbitraryJoinFlags": [],
"Env": null,
"IsExperimental": false
},
"AuthOptions": {
"CertDir": "/Users/apatil/.docker/machine/certs",
"CaCertPath": "/Users/apatil/.docker/machine/certs/ca.pem",
"CaPrivateKeyPath": "/Users/apatil/.docker/machine/certs/ca-key.pem",
"CaCertRemotePath": "",
"ServerCertPath": "/Users/apatil/.docker/machine/machines/default/server.pem",
"ServerKeyPath": "/Users/apatil/.docker/machine/machines/default/server-key.pem",
"ClientKeyPath": "/Users/apatil/.docker/machine/certs/key.pem",
"ServerCertRemotePath": "",
"ServerKeyRemotePath": "",
"ClientCertPath": "/Users/apatil/.docker/machine/certs/cert.pem",
"ServerCertSANs": [],
"StorePath": "/Users/apatil/.docker/machine/machines/default"
}
},
"Name": "default"
}
我从上面的命令jq获得以下错误
$ docker-machine inspect default | jq '{ConfigVersion, .Driver.{MachineName, CPU, Memory}, DriverName}'
jq: error: syntax error, unexpected FIELD (Unix shell quoting issues?) at <top-level>, line 1:
{ConfigVersion, .Driver.{MachineName, CPU, Memory}, DriverName}
jq: error: syntax error, unexpected '}', expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
{ConfigVersion, .Driver.{MachineName, CPU, Memory}, DriverName}
jq: 2 compile errors
答案 0 :(得分:2)
使用
修复它$ docker-machine inspect default |
jq '{ConfigVersion,
Driver: (.Driver|{MachineName, CPU, Memory}),
DriverName}'
{
"ConfigVersion": 3,
"Driver": {
"MachineName": "default",
"CPU": 2,
"Memory": 5120
},
"DriverName": "virtualbox"
}