I want to check if all Docker containers on a host are in "running" state. My naive approach was to print JSON output and then process that with jq
:
docker ps -a --format json | jq -r 'map(.State=="running")|all'
However, docker ps
apparently produces individual JSON objects per container, not an array of JSON objects, so the above produces the following errors:
jq: error (at :1): Cannot index string with string "State"
jq: error (at :2): Cannot index string with string "State"
...
How can I make docker ps
produce a proper JSON array?