Docker(47)- 一键安装 docker 的 shell 脚本

简介: Docker(47)- 一键安装 docker 的 shell 脚本

背景


有多个自己的云服务器,都要安装 docker,所以就尝试将安装的步骤转换成 shell 脚本,回头可以一键执行~

 

创建 shell 脚本


touch install_docker.sh

chmod777 install_docker.sh

 

一键安装 docker 的 shell 脚本


yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
echo -e " =========== 1.delete exist docker ================\n\n"
echo -e "step 1: 安装必要的一些系统工具"
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
echo -e "\n\nStep 2: 添加软件源信息,国内 Repository 更加稳定"
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
version=sudo cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'
if $version=7; then
        echo  -e "\n\nStep 3: 更新 Centos version is : $version; run yum makecache fast"
        sudo yum makecache fast
elif $version=8; then
        echo -e "\n\nStep 3: 更新Centos version is : $version; run yum makecache fast"
        sudo dnf makecache
fi
echo -e "=========== 2.完成配置 docker Repository ================\n\n"
# 安装最新版本的 Docker Engine 和 Container
sudo yum install docker-ce docker-ce-cli containerd.io
sudo yum -y install docker-ce
echo -e "=========== 3.成功安装完 docker ================\n\n"
sudo systemctl enable docker
sudo systemctl start docker
echo -e "=========== 4.自启动 docker ================\n\n"
# 1.创建一个目录
sudo mkdir -p /etc/docker
# 2.编写配置文件
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://reg-mirror.qiniu.com",
    "http://f1361db2.m.daocloud.io"
  ]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
echo -e "=========== 5.配置国内镜像加速 ================\n\n"
docker ps -a


  • 现在常用 centos 7、8,所以仅适配这两个系统安装 docker,自己实操过暂时没有问题
  • 希望有大神可以迷津指点

 

相关文章
|
5天前
|
弹性计算 运维 监控
|
5天前
|
存储 弹性计算 运维
自动化收集员工信息的Shell脚本
【4月更文挑战第30天】
6 0
|
6天前
|
弹性计算 运维 Shell
使用shell 脚本打印图形3
【4月更文挑战第29天】
13 0
|
6天前
|
存储 弹性计算 运维
使用shell 脚本打印图形2
【4月更文挑战第29天】
13 0
|
6天前
|
弹性计算 运维 Shell
使用shell 脚本打印图形1
【4月更文挑战第29天】
14 0
|
6天前
|
存储 弹性计算 运维
调整虚拟机内存参数的shell 脚本
【4月更文挑战第29天】
11 0
|
6天前
|
弹性计算 运维 Shell
一键申请多个证书 shell 脚本
【4月更文挑战第29天】
11 1
|
6天前
|
关系型数据库 MySQL Shell
备份 MySQL 的 shell 脚本(mysqldump版本)
【4月更文挑战第28天】
15 0
|
6天前
|
弹性计算 运维 Shell
从shell脚本发送邮件
【4月更文挑战第29天】
11 0
|
6天前
|
弹性计算 运维 Shell
使用 shell 脚本打印图形
【4月更文挑战第29天】
13 1