docker安装脚本,整理自阿里云镜像站

#!/bin/bash
DEBIAN=$(uname -v |grep -o Debian)
CENTOS=$( uname -r |grep -o el7)
if [ $DEBIAN ];
then
# step 1: 安装必要的一些系统工具
 sed -i 's@GRUB_CMDLINE_LINUX="@GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1 @' /etc/default/grub
 update-grub
 apt-get update
 apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
 curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
 add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/debian $(lsb_release -cs) stable"
# Step 4: 更新并安装 Docker-CE
 apt-get -y update
 apt-get -y install docker-ce
elif [ $CENTOS ];
then
# step 1: 安装必要的一些系统工具
 yum install -y yum-utils device-mapper-persistent-data lvm2
 sed -i 's@GRUB_CMDLINE_LINUX="@GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1 @' /etc/default/grub
 grub2-mkconfig -o /boot/grub2/grub.cfg
# Step 2: 添加软件源信息
 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装 Docker-CE
 yum makecache fast
 yum -y install docker-ce
# Step 4: 开启Docker服务
 service docker start
else
 echo "unkown release"
 exit 1
fi
#配置docker镜像加速源,此为国内第三方镜像站,用着挺快的,有更好的欢迎推荐
#添加自启,重启服务
systemctl enable docker
systemctl restart docker
原文地址:https://www.cnblogs.com/kcrist/p/9808495.html