企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
``` #!/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 ```