Issue
This is a manifest.json
generated by "docker save
" on Ubuntu:
[
{
"Config":"a5a29aeb4d6a28cb5a0b759572ae5696f0a99a4be39aa4de08d8a897e6d12b95.json",
"RepoTags":["hello/world:latest"],
"Layers":["b0e93b0b2e63771ea0cd34f350681b4397c804e5ed5ba01aec23cfaf6c49bc51/layer.tar","f9b7caaf240b159e636f77a9571073f6e4d5a0541d864ec64e4e2808b282e302/layer.tar","1355029c32eee25981e17b0e89e946d9346cffdff29ff53858104ebfe6728d80/layer.tar","362092bb6a9ed18c0e88a9b1635e7c16914661935ce64f1b581d19fd5226463a/layer.tar","fe2bde379de2f44bb47d5d75a25294485f70d8b4c7a99a08b0fcef8f4076914d/layer.tar","4acfd2b9473bf5c17f50ad2ff04c148b1be79d1174509e0fb10d27ba8cff9294/layer.tar","e5131e82e66e45e002a88618254c1cde43a497d8a94fcb5d9b20171f19b15b96/layer.tar"]
}
]
I want to use "jq
" to get the docker image name
and version
from "RepoTags
":
jq -e -r ".RepoTags" manifest.json
Here is the error:
jq: error (at manifest.json:1): Cannot index array with string "RepoTags"
How to get it with jq
?
Solution
jq -r '.[0].RepoTags[0]' manifest.json
This command breaks down as follows:
- .[0] accesses the first element of the JSON array (assuming there's only one element in the array as shown in your example).
- .RepoTags[0] accesses the first element within the "RepoTags" array, which contains the image name and version in the format hello/world:latest.
Answered By - Sathish Answer Checked By - Candace Johnson (WPSolving Volunteer)