I have a YAML file (docker-compose file in my case) that looks like this:
networks:
foo:
some_opts: "covfefe"
bar:
some_opts: "such wow"
services:
apache:
image: 'apache:1.0.0'
restart: always
mysql:
image: 'mysql:1.0.0'
restart: always
php:
image: 'php'
restart: always
I would like to extract the services name thanks to yq
, an equivalent of jq
but for YAML, to have this output:
"apache"
"mysql"
"php"
Currently I can achieve it like this:
$ cat docker-compose.yml | yq '.services' | yq 'keys[]'
"apache"
"mysql"
"php"
Even if it works, the double piped yq
seems weird to me. I think I'm doing it wrong.
Question: Is there any way to achieve it with a single yq
command ?
I tried this without success, taking inspiration from this question:
$ cat docker-compose.yml | yq '.services.keys[]'
jq: error: Cannot iterate over null
keys
is a built-in function not a property. Also thanks for the doc link :) – Attenuation