Update "hello-world/update.sh" to use "docker image inspect" instead of "docker images" (should be way faster)

This commit is contained in:
Tianon Gravi 2019-07-03 13:11:37 -07:00
parent 8a57a0ab64
commit b748abd9ea
2 changed files with 8 additions and 3 deletions

View File

@ -27,7 +27,7 @@ For more examples and ideas, visit:
$ docker images %%IMAGE%% $ docker images %%IMAGE%%
REPOSITORY TAG IMAGE ID SIZE REPOSITORY TAG IMAGE ID SIZE
hello-world latest fce289e99eb9 1.84kB hello-world latest fce289e99eb9 1840
``` ```
%%LOGO%% %%LOGO%%

View File

@ -3,7 +3,7 @@ set -Eeuo pipefail
image="${1:-hello-world}" image="${1:-hello-world}"
echo hello-world "$image" | timeout 5s xargs -P2 -n1 -rt docker pull || exit 0 echo hello-world "$image" | timeout 5s xargs -P2 -n1 docker pull &> /dev/null || exit 0
exec > "$(dirname "$(readlink -f "$BASH_SOURCE")")/content.md" exec > "$(dirname "$(readlink -f "$BASH_SOURCE")")/content.md"
@ -15,7 +15,12 @@ echo '$ docker run %%IMAGE%%'
docker run --rm hello-world docker run --rm hello-world
echo echo
echo '$ docker images %%IMAGE%%' echo '$ docker images %%IMAGE%%'
docker images "$image" | awk -F' +' 'NR == 1 || $2 == "latest" { print $1"\t"$2"\t"$3"\t"$5 }' | column -t -s$'\t' {
id="$(docker image inspect --format '{{ .Id }}' "$image:latest" | sed -r 's/^sha256:([a-f0-9]{12})[a-f0-9]+$/\1/')"
size="$(docker image inspect --format '{{ .VirtualSize }}' "$image:latest")"
echo $'REPOSITORY\tTAG\tIMAGE ID\tSIZE'
echo "$image"$'\tlatest\t'"$id"$'\t'"$size"
} | column -t -s$'\t'
echo '```' echo '```'
echo echo