1,判断容器是否存在
#判断是否存在Docker容器了
echo ${PED} | sudo docker inspect mysqlnew -f '{{.Name}}' > /dev/null
if [ $? -eq 0 ]
then
echo "已经安装过了,启动"
echo ${PED} | sudo docker start mysqlnew
echo ${PED} | sudo docker start license
exit 1
else
echo "第一次安装开始"
fi
备注:有的系统不支持上面的判断,可用下面的判断
#判断是否存在Docker容器了
if command -v echo ${PED} | sudo -S docker inspect license >/dev/null 2>&1;then
echo "启动"
echo ${PED} | sudo docker start mysqlnew
echo ${PED} | sudo docker start license
exit 0
else
echo "请先安装软件"
exit 0
fi
2,判断镜像是否存在
if test "$(docker images -q mysql-new:v1.0 2> /dev/null)" = ""
then
echo '不存在此镜像'
else
echo '存在镜像'
fi