查看docker镜像
vim /usr/bin/dockertag
#!/bin/bash
repo_url=https://hub-mirror.c.163.com
image_name=$1
tag=$2
if [[ -n "${image_name}" ]]; then
echo "Search image ${image_name} on ${repo_url}"
else
echo "Error! You should input the name of image!"
exit 1
fi
if [[ "${image_name}" != *"/"* ]]; then
image_name="library/${image_name}"
fi
tag_list=$(curl -s -S "${repo_url}/v2/${image_name}/tags/list" | jq '.tags')
for((i=$(echo ${tag_list} | jq 'length')-1;i>=0;i--)); do
t=$(echo $tag_list | jq ".[$i]" | sed 's/\"//g')
if [[ -z "${tag}" ]]; then
echo "$image_name:$t"
elif [[ "${t}" == *"${tag}"* ]]; then
echo "$image_name:$t"
fi
done
chmod 741 /usr/bin/dockertag
注意:脚本需要依赖 jq 工具
yum install jq -y
Example:
dockertag mysql;