Modifying Docker command output
Ever wanted to process the output of your favorite Docker command in a shell script?
E.g. $ docker images
|
|
Of course, the old school way would be to slice away the header row, then awk or cut your way happily through the columns you need.
But dont! Docker command-line uses a powerful feature you should learn to use:
--format <go-template>
If I wanted a simple list of all images with tags in a single string, I could just do this:
--format ' {{.Repository }}:{{.Tag}}'
|
|
And if I quickly wanted to pull/update some images, I could run:
docker images --format 'docker pull {{.Repository }}:{{.Tag}}' | sh
Hint: if you dont know which field names to use …
… or are too lazy reading Docker docs, just remember this simple format string:
--format='{{ json .}}'
It will show you all the available field names for this particular command in Json format!
|
|