Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get the image name and version from manifest.json

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading