[banner@stapp03 ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 26828d185a8f 5 seconds ago 125MB
ubuntu latest 174c8c134b2a 3 weeks ago 77.8MB
there are 2 images – i want to type command in cli and grab latest image id (first row) and use it for other subsequent commands.
Not use mouse click to select image id, how to do this?
2
Answers
We can define the format of the output for every
docker
command through--format <fmt-string>
. Details are explained on the correspondingdocs.docker.com
page.If we want the ids of all images, we can run
If we want the ids of, for example, only the ubuntu image(s), we can run
If we want to store the output of the command in a bash array, we can use
For example, a subsequent
will show us the size of the array.
If you want to print image id of the first image then you may use:
Here:
NR == 2
: Selects 2nd row{print $3}
: Prints 3rd field i.e. Image Id