Linux - Docker install

#####################

# install docker

#####################
installDocker(){

if [[ ${OS_VERSION} = "centos" ]];then

COLOR="echo -e \\033[1;31m"
END="\033[m"
VERSION="19.03.5-3.EL7"

rm -rf /etc/yum.repos.d/*

wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/repo/Centos-7.repo || { ${COLOR}"BaseOS:Can't access the internet,please check your connection!"${END};exit;}

wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/repo/epel-7.repo || { ${COLOR}"Epel:Can't access the internet,please check your connection!"${END};exit;}

wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo || { ${COLOR}"Docker-ce:Can't access the internet,please check your connection!"${END};exit;}



yum clean all

yum -y install docker-ce || { ${COLOR}"Base,Extras yum sources is unavailable, please check yum sources"${END};exit;}

mkdir -p /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://u5qp98hs.mirror.aliyuncs.com"]
}
EOF

systemctl enable --now docker
docker version && ${COLOR}"Docker install succesfully"${END} || ${COLOR}"Docker install failed"${END}

else

# ubuntu

apt update
apt -y install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -

add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt -y update
apt -y install docker-ce

systemctl enable --now docker
docker version && ${COLOR}"Docker install succesfully"${END} || ${COLOR}"Docker install failed"${END}
fi
reboot

}

 

posted @ 2021-06-08 21:28  每天都在学习的自己  阅读(67)  评论(0)    收藏  举报