docker :一键式安装docker

背景:
手动安装docker ,涉及到包安装,修改docker存储路径,配置docker加速,等等一系列操作,如果服务器较多的情况下,手动效率比较低,脚本化比较方便
说明:
1.该脚本默认安装最新版docker
2.docker使用daocloud加速器
3.私有仓库非https访问,地址根据实际情况配置
4.脚本中修复了fix the bug of container-selinux >= 2.9 安装问题
脚本:

 #! /bin/bash
set -ex
echo -e "auto install  docker" 
function  remove_old_version() {
    yum remove docker \
                      docker-client \
                      docker-client-latest \
                      docker-common \
                      docker-latest \
                      docker-latest-logrotate \
                      docker-logrotate \
                      docker-engine
};
function install_driver() {
    yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
};

function add_repo() {
   yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
    #modify repo reachable
    sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
    
};
function install_wget(){
    yum install wget -y
}
# fix the bug of container-selinux >= 2.9
function add_container_selinux() {
    install_wget
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  
    yum install epel-release -y
    yum install container-selinux -y
};
# The default choice is installed the last version of docker
function install_docker() {
   yum makecache fast -y
   yum install docker-ce docker-ce-cli containerd.io -y

};
function rpm_install_container_selinux() {
    wget http://mirrors.atosworldline.com/public/centos/7/extras/x86_64/Packages/container-selinux-2.68-1.el7.noarch.rpm
    rpm -ivh container-selinux-2.68-1.el7.noarch.rpm --nodeps --force

};
function  enable_docker(){
    systemctl  enable  docker
}

function  start_docker(){
    systemctl  start  docker
}
function  modify_docker_daemon(){
    touch  /etc/docker/daemon.json
    cat >> /etc/docker/daemon.json <<EOF  
{
  "registry-mirrors": ["http://f1361db2.m.daocloud.io"],
  "exec-opts": [
    "native.cgroupdriver=systemd"
  ],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m",
    "max-file": "5"
  },
  "insecure-registries": [
      "192.168.200.37:10000" #私有仓库地址,根据实际情况配置
  ],
  "storage-driver": "overlay2"
}

EOF
};
# make softlink for docker the dst is /data/docker
function modify_docker_storage_path(){
   systemctl  stop docker
   mv /var/lib/docker  /data/docker
   ln -s /data/docker /var/lib/docker
   systemctl  start docker
};

remove_old_version
install_driver
add_repo
add_container_selinux
if [[ $? -eq 0 ]] ; then   rpm_install_container_selinux ; fi
install_docker
enable_docker
start_docker
modify_docker_daemon
modify_docker_storage_path
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值