bash - 如何检查终端中现有的 docker 镜像?

标签 bash ubuntu unix docker

我正在从现有图像创建一个新标签。但有时图像丢失,命令失败。
所以我需要在运行命令之前检查一个 docker 镜像是否存在:

$ docker tag source:anything target:something

但是如何检查现有的 docker 镜像以及如何在终端中正确使用 if 语句?
if [docker source:anything] docker tag source:anything target:something fi

最佳答案

这是正确的方法

if [[ "$(docker images -q myimage:mytag 2> /dev/null)" == "" ]]; then

// do something

fi

你也可以使用
[ ! -z $(docker images -q myimage:mytag) ] || echo "does not exist"

关于bash - 如何检查终端中现有的 docker 镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49550645/

相关文章:

arrays - 忽略 bash 索引数组的空元素

bash - 在 bash 中只保留第一个重复条目

macos - 如何比较 (os x) bash 脚本中的 2 个(图像)文件,忽略最后更改/修改的日期 header ?

python - 如何在Ubuntu上使用多个版本的NLTK?

linux - [alternatives --config mta] 显示的意思是什么?

linux - 当在内部使用 bash 变量时,awk 命令无法按预期工作

ubuntu - 克鲁萨德 : is it possible to connect to remote server with identity file?

ubuntu - Bluemix cli panic

bash 权限被拒绝 : Can't echo to the stdin of a running process?

python - Glob 匹配除某些扩展名之外的文件