CentOS7安装Docker20.10.11

CentOS7安装Docker20.10.11

一、安装脚本

#!/bin/bash
# 定义颜色
BLUE_COLOR="\033[36m"
RED_COLOR="\033[31m"
GREEN_COLOR="\033[32m"
VIOLET_COLOR="\033[35m"
RES="\033[0m"


echo -e "${BLUE_COLOR}# ######################################################################${RES}"
echo -e "${BLUE_COLOR}#                       Docker  Install Script                       #${RES}"
echo -e "${BLUE_COLOR}# ######################################################################${RES}"

#安装依赖及工具包
yum install -y conntrack ntpdate ntp ipvsadm ipset  iptables curl sysstat libseccomp wget  vim net-tools git lrzsz

#设置防火墙
systemctl  stop firewalld  &&  systemctl  disable firewalld
yum -y install iptables-services  &&  systemctl  start iptables  &&  systemctl  enable iptables  &&  iptables -F  &&  service iptables save

#关闭selinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

# 设置系统时区为 中国/上海
timedatectl set-timezone Asia/Shanghai
# 将当前的 UTC 时间写入硬件时钟
timedatectl set-local-rtc 0

echo -e "${BLUE_COLOR}# ########################同步时钟################################${RES}"
#同步时钟
if  type ntpdate >/dev/null 2>&1; then
  ntpdate cn.pool.ntp.org 
else
  yum install -y ntpdate &&  ntpdate cn.pool.ntp.org 
fi

echo -e "${RED_COLOR}###########################开始时间:`date` #####################################${RES}"

# 检查docker
echo -e "${RED_COLOR}# ########################检查docker安装情况################################${RES}"
if   type docker >/dev/null 2>&1; then
    echo -e "docker已安装,检查通过!>>>>>>>>>>>>>>>>>>"
else
	yum install -y yum-utils device-mapper-persistent-data lvm2 gcc gcc-c++
	yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    yum makecache fast
	mkdir -p /etc/docker /docker_data
	echo '	{ ' >>  /etc/docker/daemon.json 
	echo '   "registry-mirrors": ["https://hub-mirror.c.163.com"] , ' >>  /etc/docker/daemon.json 
	echo ' 	 "graph":"/docker_data", ' >>  /etc/docker/daemon.json 
	echo ' 	 "exec-opts":["native.cgroupdriver=systemd"],  ' >>  /etc/docker/daemon.json 
	echo ' 	 "live-restore": true ' >>  /etc/docker/daemon.json 
	echo ' 	}  ' >>  /etc/docker/daemon.json 
    yum install docker-ce-20.10.11 docker-ce-cli-20.10.11 containerd.io-1.4.12 -y 
    systemctl enable docker && systemctl start docker
	echo -e "${BLUE_COLOR}##############docker安装成功!#########################${RES}"
fi

echo -e "${RED_COLOR}###########################结束时间:`date` #####################################${RES}"

二、安装

复制以下脚本,在linux的命令行窗口执行:

mkdir -p /opt/scripts
cat > /opt/scripts/dockerinstall.sh << 'EOF'
#!/bin/bash
# 定义颜色
BLUE_COLOR="\033[36m"
RED_COLOR="\033[31m"
GREEN_COLOR="\033[32m"
VIOLET_COLOR="\033[35m"
RES="\033[0m"


echo -e "${BLUE_COLOR}# ######################################################################${RES}"
echo -e "${BLUE_COLOR}#                       Docker  Install Script                       #${RES}"
echo -e "${BLUE_COLOR}# ######################################################################${RES}"

#安装依赖及工具包
yum install -y conntrack ntpdate ntp ipvsadm ipset  iptables curl sysstat libseccomp wget  vim net-tools git lrzsz

#设置防火墙
systemctl  stop firewalld  &&  systemctl  disable firewalld
yum -y install iptables-services  &&  systemctl  start iptables  &&  systemctl  enable iptables  &&  iptables -F  &&  service iptables save

#关闭selinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

# 设置系统时区为 中国/上海
timedatectl set-timezone Asia/Shanghai
# 将当前的 UTC 时间写入硬件时钟
timedatectl set-local-rtc 0

echo -e "${BLUE_COLOR}# ########################同步时钟################################${RES}"
#同步时钟
if  type ntpdate >/dev/null 2>&1; then
  ntpdate cn.pool.ntp.org 
else
  yum install -y ntpdate &&  ntpdate cn.pool.ntp.org 
fi

echo -e "${RED_COLOR}###########################开始时间:`date` #####################################${RES}"

# 检查docker
echo -e "${RED_COLOR}# ########################检查docker安装情况################################${RES}"
if   type docker >/dev/null 2>&1; then
    echo -e "docker已安装,检查通过!>>>>>>>>>>>>>>>>>>"
else
	yum install -y yum-utils device-mapper-persistent-data lvm2 gcc gcc-c++
	yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    yum makecache fast
	mkdir -p /etc/docker /docker_data
	echo '	{ ' >>  /etc/docker/daemon.json 
	echo '   "registry-mirrors": ["https://hub-mirror.c.163.com"] , ' >>  /etc/docker/daemon.json 
	echo ' 	 "graph":"/docker_data", ' >>  /etc/docker/daemon.json 
	echo ' 	 "exec-opts":["native.cgroupdriver=systemd"],  ' >>  /etc/docker/daemon.json 
	echo ' 	 "live-restore": true ' >>  /etc/docker/daemon.json 
	echo ' 	}  ' >>  /etc/docker/daemon.json 
    yum install docker-ce-20.10.11 docker-ce-cli-20.10.11 containerd.io-1.4.12 -y 
    systemctl enable docker && systemctl start docker
	echo -e "${BLUE_COLOR}##############docker安装成功!#########################${RES}"
fi

echo -e "${RED_COLOR}###########################结束时间:`date` #####################################${RES}"
EOF
bash /opt/scripts/dockerinstall.sh

三、验证

[root@localhost ~]# docker -v
Docker version 20.10.11, build dea9396
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值