#!/bin/bash env(){ echo -e "\e[1;33m perparing env!!!\e[0m" yum install -y yum-utils yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo if [ -f /etc/yum.repos.d/docker-ce.repo ];then echo -e "\e[1;32m yum源已经存在\e[0m" else echo -e "\e[1;31m yum源不存在\e[0m" fi } install_docker_engine(){ echo -e "\e[3;32m----------------------------------------------------------------------------------------------------\e[0m" echo -e "\e[2;33m 以下是docker版本列表:\e[0m" yum list docker-ce --showduplicates | sort -r | grep el7 read -p "请在上面的列表中选择并输入您要安装的docker版本(example:3:20.10.11-3.el7;输入:20.10.11):" version yum install -y docker-ce-$version docker-ce-cli-$version containerd.io docker-compose-plugin if [ $? -eq 0 ];then echo -e "\e[1,32m docker-$version 版本安装成功,正在启动中......\e[0m" systemctl start docker if [ $? -eq 0 ];then sleep 4 systemctl status docker echo -e "\e[1,32m docker启动成功!\e[0m" else echo -e "\e[1,31m docker启动失败!\e[0m" fi else echo -e "\e[1,31m docker安装失败,请检查日志...\e[0m" fi } remove_old_version (){ echo -e "\e[1;33m remove docker old version!\e[0m" yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine if [ $? -eq 0 ];then echo -e "\e[1;32m remove docker old version successful!!!\e[0m" sleep 5 else echo -e "\e[1;31m please check \e[0m" fi } image_speed_up () { echo -e "\033[1;33m正在添加镜像加速地址......\e[0m" cat >> /etc/docker/daemon.json << EOF { "registry-mirrors": ["https://bm19jwri.mirror.aliyuncs.com"] } EOF echo -e "\033[1;32m添加成功!!!\e[0m" systemctl daemon-reload && systemctl restart docker } remove_old_version env install_docker_engine image_speed_up
标签:脚本,在线,ce,echo,version,yum,docker,0m From: https://www.cnblogs.com/shuiyuesheng/p/17014724.html