I am having some difficulty understanding how to make use of docker's --format option.
For example, if I run 'docker images' i get the following:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
repo1 305 123456678676 4 hours ago 500MB
repo1 latest 123431241245 4 hours ago 500MB
repo2 305 135151251531 4 hours ago 2.39GB
I would like to get results for the images of 'repo1', in JSON format. I found the following page: https://docs.docker.com/config/formatting/ . For the 'json' example, it mentions 'go formatting' is used, however the link provided I am having a hard time making the connection. And the json example on the page is only for a single column. I'm having difficulty figuring out how to get all of the columns, but only for certain repo images.
Also - does anyone know if this is backwards compatible? I will need it to work on older versions of docker, so if it is only available on newer version, maybe it's best to parse the output myself. I can not use docker APIs.
The OCI format is a specification for container images based on the Docker Image Manifest Version 2, Schema 2 format. Container Registry supports pushing and pulling OCI images.
By default, docker inspect will render results in a JSON array.
A Docker image is a file used to execute code in a Docker container. Docker images act as a set of instructions to build a Docker container, like a template. Docker images also act as the starting point when using Docker. An image is comparable to a snapshot in virtual machine (VM) environments.
The docker images command can limit images to a specific repository. This page also shows formatting tips.
Eg,
docker images repo1 --format "{{json . }}"
Note the format is evaluated once per image, not as a collection of images.
For completeness, see Go's template formatting syntax.
This style of formatting has been in place for a while, but you'd probably want to double check past versions of docker behave as you expect.
See also format docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With