From b748abd9eabcd7935e8efcf41c818a31d506047c Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Wed, 3 Jul 2019 13:11:37 -0700 Subject: [PATCH] Update "hello-world/update.sh" to use "docker image inspect" instead of "docker images" (should be way faster) --- hello-world/content.md | 2 +- hello-world/update.sh | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hello-world/content.md b/hello-world/content.md index 752cb4dbf..105f8364c 100644 --- a/hello-world/content.md +++ b/hello-world/content.md @@ -27,7 +27,7 @@ For more examples and ideas, visit: $ docker images %%IMAGE%% REPOSITORY TAG IMAGE ID SIZE -hello-world latest fce289e99eb9 1.84kB +hello-world latest fce289e99eb9 1840 ``` %%LOGO%% diff --git a/hello-world/update.sh b/hello-world/update.sh index 5084c41f8..505ed6490 100755 --- a/hello-world/update.sh +++ b/hello-world/update.sh @@ -3,7 +3,7 @@ set -Eeuo pipefail 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" @@ -15,7 +15,12 @@ echo '$ docker run %%IMAGE%%' docker run --rm hello-world echo 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