码迷,mamicode.com
首页 > 其他好文 > 详细

23.第17章 企业级容器技术docker

时间:2021-01-12 10:59:28      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:改版   数字   curl   cli   lease   mon   tab   检查   ubuntu   

一.dosker一键安装

#docker1903版本一键安装
#!/bin/bash
#
#********************************************************************
#Author:		    zhanghui
#QQ: 			    19661891
#Date: 			    2021-01-08
#FileName:		    install_docker_for_docker1903.sh
#URL: 			    www.neteagles.cn
#Description:		The test script
#Copyright (C): 	2021 All rights reserved
#********************************************************************
COLOR="echo -e \\E[1;32m"
END="\\E[0m"

ubuntu_install_docker(){
dpkg -s docker-ce &>/dev/null && ${COLOR}"Docker已安装,退出"${END} && exit
local DOCKER_VERSION="5:19.03.14~3-0~ubuntu-`lsb_release -cs`"
apt update
apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository  "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu  $(lsb_release -cs) stable"
apt update

${COLOR}"Docker有以下版本"${END}
apt-cache madison docker-ce
${COLOR}"5秒后即将安装:Docker-"${DOCKER_VERSION}"版本......"${END}
${COLOR}"如果想安装其它Docker版本,请按Ctrl+c键退出,修改版本再执行"${END}
sleep 5

apt -y install docker-ce=${DOCKER_VERSION} docker-ce-cli=${DOCKER_VERSION}
}

centos_install_docker(){
rpm -q docker-ce &> /dev/null && ${COLOR}"Docker已安装,退出"${END} && exit
rpm -q redhat-lsb-core &> /dev/null || yum -y install redhat-lsb-core
os_version=`lsb_release -rs |awk -F. ‘{print $1}‘`
local DOCKER_VERSION="19.03.14-3.el`lsb_release -rs |awk -F. ‘{print $1}‘`"
cat > /etc/yum.repos.d/docker.repo <<EOF
[docker]
name=docker
gpgcheck=0
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/$os_version/x86_64/stable/
EOF
yum clean all

${COLOR}"Docker有以下版本"${END}
yum list docker-ce.x86_64 --showduplicates  |grep docker-ce |sort -nr
${COLOR}"10秒后即将安装:Docker-"${DOCKER_VERSION}"版本......"${END}
${COLOR}"如果想安装其它Docker版本,请按Ctrl+c键退出,修改版本再执行"${END}
sleep 10

yum -y install docker-ce-$DOCKER_VERSION docker-ce-cli-$DOCKER_VERSION || { ${COLOR}"Base,Extras的yum源失败,请检查yum配置"${END};exit; }
}

aliyun_jxjsq(){
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-‘EOF‘
{
  "registry-mirrors": ["https://hzw5xiv7.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl enable --now docker
docker version &&  ${COLOR}"Docker 安装成功"${END} || ${COLOR}"Docker 安装失败"${END}
}

if [ `awk -F‘"‘ ‘/^ID=/{print $2}‘ /etc/os-release` == "centos" ] &> /dev/null;then
	centos_install_docker
	aliyun_jxjsq
else
	ubuntu_install_docker
	aliyun_jxjsq
fi


#docker菜单选择版本
#!/bin/bash
#
#********************************************************************
#Author:		    zhanghui
#QQ: 			    19661891
#Date: 			    2021-01-08
#FileName:		    install_docker_2.sh
#URL: 			    www.neteagles.cn
#Description:		The test script
#Copyright (C): 	2021 All rights reserved
#********************************************************************
COLOR="echo -e \\E[1;32m"
END="\\E[0m"

ubuntu_install_docker(){
dpkg -s docker-ce &>/dev/null && ${COLOR}"Docker已安装,退出"${END} && exit
apt update
apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository  "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu  $(lsb_release -cs) stable"
apt update

${COLOR}"Docker有以下版本"${END}
apt-cache madison docker-ce
${COLOR}"5秒后即将安装:Docker-"${DOCKER_VERSION}"版本......"${END}
${COLOR}"如果想安装其它Docker版本,请按Ctrl+c键退出,修改版本再执行"${END}
sleep 5

apt -y install docker-ce=${DOCKER_VERSION} docker-ce-cli=${DOCKER_VERSION}
}

ubuntu_docker_version_2010(){
DOCKER_VERSION="5:20.10.2~3-0~ubuntu-`lsb_release -cs`"
}

ubuntu_docker_version_1903(){
DOCKER_VERSION="5:19.03.14~3-0~ubuntu-`lsb_release -cs`"
}

ubuntu_docker_version_1809(){
DOCKER_VERSION="5:18.09.9~3-0~ubuntu-`lsb_release -cs`"
}

centos_install_docker(){
rpm -q docker-ce &> /dev/null && ${COLOR}"Docker已安装,退出"${END} && exit
os_version=`lsb_release -rs |awk -F. ‘{print $1}‘`
cat > /etc/yum.repos.d/docker.repo <<EOF
[docker]
name=docker
gpgcheck=0
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/$os_version/x86_64/stable/
EOF
yum clean all

${COLOR}"Docker有以下版本"${END}
yum list docker-ce.x86_64 --showduplicates |grep docker-ce |sort -nr
${COLOR}"10秒后即将安装:Docker-"${DOCKER_VERSION}"版本......"${END}
${COLOR}"如果想安装其它Docker版本,请按Ctrl+c键退出,修改版本再执行"${END}
sleep 10

yum -y install docker-ce-$DOCKER_VERSION docker-ce-cli-$DOCKER_VERSION || { ${COLOR}"Base,Extras的yum源失败,请检查yum配置"${END};exit; }
}

check_lsb(){
rpm -q redhat-lsb-core &> /dev/null || yum -y install redhat-lsb-core
}

centos_docker_version_2010(){
DOCKER_VERSION="20.10.2-3.el`lsb_release -rs |awk -F. ‘{print $1}‘`"
}

centos_docker_version_1903(){
DOCKER_VERSION="19.03.14-3.el`lsb_release -rs |awk -F. ‘{print $1}‘`"
}

centos_docker_version_1809(){
DOCKER_VERSION="18.09.9-3.el`lsb_release -rs |awk -F. ‘{print $1}‘`"
}

centos_docker_version_1712(){
DOCKER_VERSION="17.12.1.ce-1.el`lsb_release -rs |awk -F. ‘{print $1}‘`.centos"
}

aliyun_jxjsq(){
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-‘EOF‘
{
  "registry-mirrors": ["https://hzw5xiv7.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl enable --now docker
docker version &&  ${COLOR}"Docker 安装成功"${END} || ${COLOR}"Docker 安装失败"${END}
}

PS3="请选择相应的Docker版本(1-8):" 
MENU="
Ubuntu_Docker_5:20.10.2~3-0版本
Ubuntu_Docker_5:19.03.14~3-0版本
Ubuntu_Docker_5:18.09.9~3-0版本
CentOS_Docker_20.10.2-3版本
CentOS_Docker_19.03.14-3版本
CentOS_Docker_18.09.9-3版本
CentOS_Docker_17.12.1.ce-1版本
退出
"

select menu in $MENU;do
case $REPLY in
1)
    ubuntu_docker_version_2010
    ubuntu_install_docker
    aliyun_jxjsq
	break
    ;;
2)
    ubuntu_docker_version_1903
    ubuntu_install_docker
    aliyun_jxjsq
	break
    ;;
3)
    ubuntu_docker_version_1809
    ubuntu_install_docker
    aliyun_jxjsq
	break
    ;;
4)
    check_lsb
    centos_docker_version_2010
    centos_install_docker
    aliyun_jxjsq
	break
    ;;
5)
    check_lsb
    centos_docker_version_1903
    centos_install_docker
    aliyun_jxjsq
	break
    ;;
6)
    check_lsb
    centos_docker_version_1809
    centos_install_docker
    aliyun_jxjsq
	break
    ;;	
7)
    check_lsb
    centos_docker_version_1712
    centos_install_docker
    aliyun_jxjsq
	break
    ;; 
8)
    break
    ;;
*)
    echo -e "\e[1;31m输入错误,请输入正确的数字(1-8)!\e[0m"
    ;; 
esac
done

#docker手动输入版本
#!/bin/bash
#
#********************************************************************
#Author:		    zhanghui
#QQ: 			    19661891
#Date: 			    2021-01-09
#FileName:		    install_docker_3.sh
#URL: 			    www.neteagles.cn
#Description:		The test script
#Copyright (C): 	2021 All rights reserved
#********************************************************************
COLOR="echo -e \\E[1;32m"
END="\\E[0m"

ubuntu_install_docker(){
dpkg -s docker-ce &>/dev/null && ${COLOR}"Docker已安装,退出"${END} && exit
apt update
apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository  "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu  $(lsb_release -cs) stable"
apt update

${COLOR}"Docker有以下版本"${END}
apt-cache madison docker-ce
read -p "请输入要安装Docker版本(例如:5:19.03.14~3-0~ubuntu-bionic):" DOCKER_VERSION
${COLOR}"5秒后即将安装:Docker-"${DOCKER_VERSION}"版本......"${END}
${COLOR}"如果想安装其它Docker版本,请按Ctrl+c键退出,重新输入版本再执行"${END}
sleep 5

apt -y install docker-ce=${DOCKER_VERSION} docker-ce-cli=${DOCKER_VERSION}
}

centos_install_docker(){
rpm -q docker-ce &> /dev/null && ${COLOR}"Docker已安装,退出"${END} && exit
rpm -q redhat-lsb-core &> /dev/null || yum -y install redhat-lsb-core
os_version=`lsb_release -rs |awk -F. ‘{print $1}‘`
cat > /etc/yum.repos.d/docker.repo <<EOF
[docker]
name=docker
gpgcheck=0
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/$os_version/x86_64/stable/
EOF
yum clean all

${COLOR}"Docker有以下版本"${END}
yum list docker-ce.x86_64 --showduplicates |grep docker-ce |sort -nr
read -p "请输入要安装Docker版本(例如:19.03.14-3.el8):" DOCKER_VERSION
${COLOR}"5秒后即将安装:Docker-"${DOCKER_VERSION}"版本......"${END}
${COLOR}"如果想安装其它Docker版本,请按Ctrl+c键退出,重新输入版本再执行"${END}
sleep 5

yum -y install docker-ce-$DOCKER_VERSION docker-ce-cli-$DOCKER_VERSION || { ${COLOR}"Base,Extras的yum源失败,请检查yum配置"${END};exit; }
}

aliyun_jxjsq(){
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-‘EOF‘
{
  "registry-mirrors": ["https://hzw5xiv7.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl enable --now docker
docker version &&  ${COLOR}"Docker 安装成功"${END} || ${COLOR}"Docker 安装失败"${END}
}

if [ `awk -F‘"‘ ‘/^ID=/{print $2}‘ /etc/os-release` == "centos" ] &> /dev/null;then
	centos_install_docker
	aliyun_jxjsq
else
	ubuntu_install_docker
	aliyun_jxjsq
fi

23.第17章 企业级容器技术docker

标签:改版   数字   curl   cli   lease   mon   tab   检查   ubuntu   

原文地址:https://www.cnblogs.com/neteagles/p/14257143.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!