```
#!/bin/bash
#runcon = docker ps | grep -v CONTAINER | awk '{print $2}'
#set -x
loginfo()
{
/usr/bin/echo -e "$(date +"%Y-%m-%d") $(date +"%H:%M:%S") [INFO] $1"
}
logerror()
{
/usr/bin/echo -e "$(date +"%Y-%m-%d") $(date +"%H:%M:%S") [ERROR] $1"
}
clearcontainner()
{
if [ $(docker ps -a | grep -v CONTAINER | grep -v 'Up' | wc -l) -gt 0 ];then
docker ps -a | grep -v CONTAINER | grep -v 'Up' | awk '{print $1}' | xargs docker rm -f
else
echo "没有需要删除的容器"
fi
}
clearuntagimage()
{
if [ $(docker images | grep -v REPOSITORY | grep '<none>'| wc -l) -gt 0 ];then
docker images | grep -v REPOSITORY | grep '<none>' | awk '{print $3}'| xargs docker rmi -f
else
echo "没有未打标签的镜像"
fi
}
clearimage()
{
for exsitimage in $(docker images |grep -v REPOSITORY | awk '{print $1":"$2}')
do
export isdeleteflag=1
for runimage in $(docker ps | grep -v CONTAINER | awk '{print $2}')
do
if [ $exsitimage = $runimage ];then
echo $exsitimage"此镜像有运行的容器,不可以删除"
export isdeleteflag=0
break
elif [ $(echo $exsitimage | grep latest | wc -l) -eq 1 ] && [ $exsitimage = $(echo $runimage":"latest) ];then
echo $exsitimage"此镜像有运行的容器,不可以删除"
export isdeleteflag=0
break
fi
done
if [ $isdeleteflag = 1 ];then
echo $exsitimage"此镜像没有运行的容器,可以删除"
docker rmi -f $exsitimage
fi
done
}
chk_image()
{
image_count=$(docker image ls | grep $1 | wc -l)
echo "=========$1 image count = $image_count"
if [ $image_count -eq 0 ]; then
if [ $1 == "tomcat" ]; then
echo "=========load tomat image..."
docker tag f5a3ab348f2d 136.160.23.254:5000/tomcat:8.5.20.4
elif [ $1 == "registry" ]; then
echo "=========load repository image..."
docker load -i /data/hps/image/registry/registry_v1.tar
else
echo "=========unknow image..."
fi
else
echo "=========$1 image exist..."
fi
}
chk_repository()
{
chk_image "registry"
chk_image "tomcat"
if [ $(docker ps | grep registry |grep "Up *" | wc -l) -eq 1 ]; then
echo "=========registry is running..."
else
echo "=========registry process may be dead..."
echo "=========startting registry..."
docker run -d -e SETTINGS_FLAVOR=dev -e STORAGE_PATH=/tmp/registry -v /data/hps/image:/tmp/registry -p 5000:5000 --restart=always registry
echo "=========registry start successfully..."
fi
}
#echo $runcon
main()
{
clearcontainner
clearuntagimage
clearimage
chk_repository
}
main
```
- docker
- docker安装
- 数据持久化
- 镜像管理
- Dockerfile
- 镜像的分层
- add copy
- 构建实例
- 镜像的导入导出
- 清理构建空间
- 配置阿里云加速器
- docker网络模型
- 本地仓库
- registry
- harbor
- IDEA部署docker
- 软件安装
- 安装es
- 安装MongoDB
- 安装rabbitmq
- 安装redis
- 安装nacos
- 安装mysql
- Minio
- 镜像中心
- kubernetes
- 1. 安装k8s
- 2.主要组件
- 3.污点
- 4.pod
- 5.控制器
- 6.网络
- 7.探针
- 8.安装Dashbord
- 9.secret
- 9.serviceAccount
- 10.service
- 资源清单
- kube-proxy
- flannel源文件
- 服务升级
- 笔记
- 镜像