基于docker-compose使用shell搭建harbor私有仓库

版本:harbor-offline-installer-v2.2.3

提前下载好docker-compose,脚本环境为离线安装;

 1 #!/bin/bash
 2 workdir=$(pwd `dirname $0`)
 3 
 4 if [ ! -f $workdir/docker-compose ];then
 5         echo "docker-compose file is not exists." ;exit 1
 6 fi
 7 if [ ! -x $workdir/docker-compose ];then
 8         chmod +x $workdir/docker-compose
 9 fi
10 if [ -f /usr/local/bin/docker-compose ];then
11         echo "Execution file of docker-compose is already exists"; exit 1
12 fi
13 
14 cp -r $workdir/docker-compose /usr/local/bin/docker-compose
15 
16 if [ ! -f $workdir/harbor-offline-installer-v2.2.3.tgz ];then
17         echo "harbor-offine file is not exists,please check it"; exit 1
18 fi
19 read -ep "Please input derectory of harbor server: " HB
20 if [ ! -d $HB ];then
21         mkdir $HB
22 elif [ -d $HB/harbor ];then
23         echo "The target file is already exists,Please check it";exit 1
24 fi
25 tar -xvf $workdir/harbor-offline-installer-v2.2.3.tgz -C $HB &> /dev/null
26 usage=$HB/harbor
27 cp $usage/harbor.yml.tmpl $usage/harbor.yml
28 read -ep "Please input ip of harbor server:" IP
29 sed -ri "s/^hostname(.*)/hostname: $IP/g" $usage/harbor.yml
30 read -ep "Please input port number of harbor server: " PORT
31 sed -ri "s/port: 80/port: $PORT/g" $usage/harbor.yml
32 sed -ri "s/^(https)/#\1/g" $usage/harbor.yml
33 sed -ri "s/(port: 443)/#\1/g" $usage/harbor.yml
34 HOSTNAME=`cat $usage/harbor.yml |grep ^hostname |cut -d ' ' -f 2`
35 PORT=`cat $usage/harbor.yml |grep -v "#" |grep port |tr -s ' '|cut -d ' ' -f3`
36 PASSWD=`cat $usage/harbor.yml |grep -v "#"|grep -w harbor_admin_password |cut -d' ' -f 2`
37 echo -e "\033[35m ……url for harbor server is : $HOSTNAME:$PORT……\033[0m"
38 echo -e "\033[31m ……password for harbor server is : $PASSWD……\033[31m"
39 docker load -i $usage/harbor.v2.2.3.tar.gz
40 bash $usage/prepare &> /dev/null
41 bash $usage/install &> /dev/null
42 cd $usage
43 docker-compose up -d
44 docker ps -a

 

上一篇:易错点


下一篇:消耗cpu资源的脚本