Просмотр исходного кода

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

Tianon Gravi 6 лет назад
Родитель
Сommit
b748abd9ea
2 измененных файлов с 8 добавлено и 3 удалено
  1. 1 1
      hello-world/content.md
  2. 7 2
      hello-world/update.sh

+ 1 - 1
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%%

+ 7 - 2
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