docker容器部署gitlab

83284950 2020-04-17

#!/bin/bash

serverName="gitlab"
imageName="gitlab/gitlab-ce:latest"
#imageName="gitlab/gitlab-ee:latest"

function runServer(){
    docker run --detach         -p 9443:443         -p 9080:80         -p 10022:22         --name ${serverName}         -/gitlab-data/etc:/etc/gitlab         -/gitlab-data/log:/var/log/gitlab         -/gitlab-data/data:/var/opt/gitlab         -v /etc/localtime:/etc/localtime         --restart=unless-stopped         ${imageName}
}

runningCount=`docker ps -f status=running -f status=restarting | grep -w ${serverName} |wc -l`;
if [[ ${runningCount} > 0 ]];then
    echo "docker restart 重启项目:${serverName}"
    docker restart ${serverName}
    exit 0
fi

serverCount=`docker ps -f status=exited -f status=created | grep -w ${serverName} |wc -l`;
# 判断是否已经启动过,且端口为默认端口
if [[ ${serverCount} > 0 ]];then
    if [[ ${serverCount} > 1 ]]; then
        echo "Error : 查找到多个 ${serverName} 容器,请手动启动"
        exit 1
    else
        echo "docker start 启动项目:${serverName}"
        docker start ${serverName}
    fi
else
    name=${imageName%%:*}
    tag=${imageName##*:}
    # 判断是否有该镜像
    imageCount=`docker images | grep -w ${name} | wc -l`;

    if [[ ${imageCount} > 0 ]];then
        echo "docker run 第一次启动项目: ${imageName}"
        runServer
    else
        echo "Error : 还没有该镜像"
        exit 1
    fi
fi

相关推荐

就是那个胖子 / 0评论 2020-06-15