每日一个shell脚本之一键部署Docker
源码参上
#!/usr/bin/bash # **************************************# CSDN: M乔木 # qq邮箱: 2776617348@qq.com # 解释器: 这是一个shell脚本 # **************************************#声明函数function Aq_jc(){clear#检测防火墙selinuxecho "------------------------------------------------------------"echo "[1]开始检测防火墙SeLinux是否关闭..."sleep 1f_w=`systemctl status firewalld | awk '/Active:/{print $2}'`s_l=`getenforce`#判断是否关闭 没关闭就结束运行if [ ${f_w} = "inactive" -a ${s_l} = "Disabled" ];thenecho "[2]防火墙SeLinux已关闭..."sleep 1echo "[3]正在飞速安装docker中..."sleep 1elseecho "[2]防火墙SeLinux未关闭..."systemctl disable firewalld &>/dev/nullsed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinuxsed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config sleep 1echo "[3]正在关闭..."sleep 1echo "[4]防火墙SeLinux已关闭 请重启机器生效..."echo "------------------------------------------------------------"exit 0fi#防火墙关了的话就继续开启路由转发echo "[4]正在开启路由转发虚拟网桥..."echo 'net.ipv4.ip_forward =1' >>/etc/sysctl.confecho 'net.bridge.bridge-nf-call-iptables =1' >>/etc/sysctl.confecho 'net.bridge.bridge-nf-call-ip6tables =1' >>/etc/sysctl.confsysctl -p &>/dev/nullsleep 1#防火墙关闭的话就清理docker环境echo "[5]正在清理环境中..."yum -y remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine &>/dev/nullsleep 1echo "[6]开始安装docker依赖..."yum install -y yum-utils device-mapper-persistent-data lvm2 &>/dev/nullsleep 1echo "[7]开始配置阿里docker源..."yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo &>/dev/nullyum clean all &>/dev/null && yum makecache fast &>/dev/nullsleep 1echo "[8]开始安装docker..."yum -y install docker-ce doker-ce-cli containerd.io &>/dev/nullsleep 1echo "[9]开始配置开机自启..."systemctl start docker &>/dev/nullsystemctl enable docker &>/dev/nullsystemctl restart docker &>/dev/nullsleep 1echo "[10]开始配置阿里云镜像加速器..."clearecho "[11]开始建立docker加速器放置目录..."mkdir -p /etc/dockersleep 1echo "[12]开始写入配置..."
tee /etc/docker/daemon.json &>/dev/null<<-'EOF'
{"registry-mirrors": ["https://2zwkpj0m.mirror.aliyuncs.com"]
}
EOFsleep 1echo "[13]重新加载system工具..."systemctl daemon-reload &>/dev/nullsleep 1echo "[14]重新启动docker..."systemctl restart docker &>/dev/nullsleep 1echo "[15]阿里云镜像加速器配置完毕!"sleep 1echo "[16]开始拉取基础镜像centos:7..."docker pull centos:7 &>/dev/nullsleep 1echo "[17]已部署docker及第一个基础镜像centos7已配置完毕!"sleep 1echo '[18]开始使用你的一个docker命令体验激动人心的docker吧!'sleep 1echo '[19]docker images:查看已下载镜像'sleep 1echo '[20]docker info:查看docker基本信息'sleep 1echo '[21]docker run -it centos:7 /bin/bash:以centos7为基础启动一个容器'echo "------------------------------------------------------------"}#主界面Aq_jc
使用方法
[root@qm ]# vim docker-az.sh
#复制粘贴上面的代码进去[root@qm ]# sh docker-az.sh
#运行脚本
结尾
还是那话点赞关注转发感谢!