docker安装脚本
#!/bin/bash
os_ver=`cat /etc/os-release |grep -w 'NAME'|cut -d "=" -f2`
rhos7=`cat /proc/version|cut -d " " -f3|grep -o el7`
rhos8=`cat /proc/version|cut -d " " -f3|grep -o el8`
rh_dkos=19.03.15-3.
ub_dkos=19.03.15~3
case $os_ver in
'"CentOS Linux"')
echo 'PC os is centos linux'
if [ $rhos7 = 'el7' ] ;then
rh_dkos=19.03.15-3.${rhos7}
cd /etc/yum.repos.d/ ;mkdir bak ;mv * bak/
wget -O /etc/yum.repos.d/ctos7.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel7.repo https://mirrors.aliyun.com/repo/epel-7.repo
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all ;yum makecache
yum list --showduplicates docker-ce &>/dev/null ||echo '镜像源错误,请修改...' && exit 1
sleep 1
yum install -y docker-ce-${rh_dkos} docker-ce-cli-${rh_dkos}||echo "安装失败" && exit 1
mkdir /etc/docker &>/dev/null &&echo "正在设置docker镜像加速";sleep 1
tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://2ynvugig.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl start docker
echo "安装完成,服务已启动" && exit 0
elif [ $rhos8 = 'el8' ] ;then
rh_dkos=19.03.15-3.${rhos8}
cd /etc/yum.repos.d/ ;mkdir bak ;mv * bak/
wget -O /etc/yum.repos.d/ctos8.repo https://mirrors.aliyun.com/repo/Centos-8.repo
wget https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm ;yum install -y epel-release-latest-8.noarch.rpm
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all ;yum makecache
yum list --showduplicates docker-ce &>/dev/null && echo "镜像源配置成功" ||echo "镜像源错误,请修改..."
sleep 1
yum install -y docker-ce-${rh_dkos} docker-ce-cli-${rh_dkos} && echo "安装成功,正在启动服务..."||echo "安装失败"
mkdir /etc/docker &>/dev/null ;echo "正在设置docker镜像加速";sleep 1
tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://2ynvugig.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl start docker
echo "安装完成,服务已启动" && exit 0
fi
;;
'"Ubuntu"')
echo '系统是Ubuntu'
sleep 1;echo "正在设置镜像源";cp /etc/apt/sources.list{,.bak}
tee /etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
apt-get update
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt_docker_vs=`apt-cache madison docker-ce|sed -nr "/${ub_dkos}/s#.*(docker-ce) \| (.*)\|.*#\1=\2#p"`
apt_docker_cli_vs=`apt-cache madison docker-ce|sed -nr "/${ub_dkos}/s#.*(docker-ce-cli) \| (.*)\|.*#\1=\2#p"`
apt install -y $apt_docker_vs $apt_docker_cli_vs
sleep 1
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://2ynvugig.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload;systemctl restart docker
echo "安装完成,服务已启动" && wait
;;
*)
echo 'unknow the system'
;;
esac