实现

1、检查内核版本

2、检查docker是否已安装

3、安装docker,如因网络等原因失败循环安装至安装完成

#!/bin/bash

#file:docker_install.sh

#From:suminem

function docker_choice()
{
  echo "检查内核版本......"
  yum -y install bc &> /dev/null
  kenel=`uname -r`
  kenel=`echo ${kenel:0:3}` #从第一个开始向后取3个字符
  if [ $(echo "${kenel} >= 3.10" | bc) = 1 ];then
    echo "检查Docker......!"
    docker -v &> /dev/null
    a=`echo $?`
    while [ $a -ne 0 ]; do
      echo "安装docker环境..."
      echo "安装基础依赖..."
      yum install yum-utils device-mapper-persistent-data lvm2 -y &> /dev/null
      echo "安装docker-ce.repo"
      yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo &> /dev/null
      yum update &> /dev/null
	  yum makecache fast &> /dev/null
      echo "安装docker环境..."
      yum install containerd.io docker-ce-19.03.8 docker-ce-cli-19.03.8 -y
      docker -v &> /dev/null
      a=`echo $?`
    done
    echo "安装完成!启动Docker"
    systemctl start docker
    systemctl enable docker &> /dev/null
    else
  echo "内核版本太低,请您升级内核版本!"

  fi

}

  

# 执行函数
docker_choice

 

docker阿里云加速

sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://gbpursha.mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload

sudo systemctl restart docker