docker-各个版本docker一件安装脚本

宇文和昶
2023-12-01

ubuntu 1804

#!/bin/bash
#Description: Install docker on Ubuntu1804
#Version:1.0
#Date:2020-01-22
COLOR="echo -e \\033[1;31m"
END="\033[m"
DOCKER_VERSION="5:19.03.5~3-0~ubuntu-bionic"
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.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key
add -
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/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}
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
 "registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl enable --now docker
docker version && ${COLOR}"Docker 安装成功"${END} ||  ${COLOR}"Docker 安装失
败"${END}
}
install_docker

CentOS 8

#!/bin/bash
. /etc/init.d/functions
COLOR="echo -e \\E[1;32m"
END="\\E[0m"
DOCKER_VERSION="-19.03.13-3.el8"
install_docker() {                                                              
                             
   ${COLOR}"开始安装 Docker....."${END}
   sleep 1
cat > /etc/yum.repos.d/docker.repo <<EOF
[docker]
name=docker
gpgcheck=0
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/
EOF
  yum clean all
  yum -y install docker-ce$DOCKER_VERSION docker-ce-cli$DOCKER_VERSION \
      || { ${COLOR}"Base,Extras的yum源失败,请检查yum源配置"${END};exit; }
   mkdir -p /etc/docker
   cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
}
EOF
  systemctl enable --now docker
  docker version && ${COLOR}"Docker安装成功"${END} || ${COLOR}"Docker安装失
败"${END}
}
rpm -q docker-ce &> /dev/null && action "Docker已安装" || install_docker

早期CentOS8无yum仓库,可以利用下面脚本安装docker

#!/bin/bash
. /etc/init.d/functions
COLOR="echo -e \\E[1;32m"
END="\\E[0m"
DOCKER_VERSION="-19.03.8-3.el7"
install_docker() {                                                              
                             
   ${COLOR}"开始安装 Docker....."${END}
   sleep 1
   wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker
ce/linux/centos/docker-ce.repo || { ${COLOR}"
互联网连接失败,请检查网络配置!"${END};exit; }
  yum clean all
  dnf -y install https://mirrors.aliyun.com/docker
ce/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.1.el7.x86_64.rpm
  yum -y install docker-ce$DOCKER_VERSION docker-ce-cli$DOCKER_VERSION \
      || { ${COLOR}"Base,Extras的yum源失败,请检查yum源配置"${END};exit; }
   mkdir -p /etc/docker
   cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
}
EOF
  systemctl enable --now docker
  docker version && ${COLOR}"Docker安装成功"${END} || ${COLOR}"Docker安装失
败"${END}
}
rpm -q docker &> /dev/null && action "Docker已安装" || install_docker

CentOS 7

#!/bin/bash
COLOR="echo -e \\033[1;31m"
END="\033[m"
VERSION="19.03.5-3.el7"
wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker
ce/linux/centos/docker-ce.repo || { ${COLOR}"互联网连接失败,请检查网络配
置!"${END};exit; }
yum clean all
yum -y install docker-ce-$VERSION docker-ce-cli-$VERSION || {
${COLOR}"Base,Extras的yum源失败,请检查yum源配置"${END};exit; }
#使用阿里做镜像加速
mkdir -p /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
}
EOF
systemctl enable --now docker
docker version && ${COLOR}"Docker安装成功"${END} || ${COLOR}"Docker安装失败"${END}
 类似资料: