美文网首页
docker安装脚本

docker安装脚本

作者: Jsolo | 来源:发表于2020-10-17 12:59 被阅读0次

    centos下

    #!/bin/bash
    
    initDocker() {
      echo "========== initDocker =========="
    
      if ! which docker; then
        echo "安装 docker"
    
        sudo yum -y install yum-utils device-mapper-persistent-data lvm2
        sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
        sudo yum makecache fast   #更新缓存
        sudo yum -y install docker-ce  #安装软件包
        sudo systemctl start docker     #启动
        sudo systemctl enable docker   #开机启动
        sudo systemctl is-enabled docker  #检查开机状态
        sudo docker version #检查docker版本
      fi
    
      if ! which docker-compose; then
        echo "安装 docker-compose"
        sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
        sudo chmod +x /usr/local/bin/docker-compose
        docker-compose --version
      fi
    }
    
    initDocker
    
    

    ubuntu

    #!/bin/bash
    
    updateSourceList() {
      echo "========== updateSourceList =========="
      if ! cat /etc/apt/sources.list | grep 'aliyun.com' >/dev/null; then
        sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
    
        echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" >>/etc/apt/sources.list
        echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >>/etc/apt/sources.list
        echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >>/etc/apt/sources.list
        echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >>/etc/apt/sources.list
        echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" >>/etc/apt/sources.list
        echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >>/etc/apt/sources.list
        echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >>/etc/apt/sources.list
        echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >>/etc/apt/sources.list
    
        apt-get update
      fi
    }
    
    initDocker() {
      echo "========== initDocker =========="
    
      if ! which docker; then
        echo "安装 docker"
    
        sudo apt-get purge -y docker-ce
        sudo apt-get purge -y docker-ee
        sudo rm -rf /var/lib/docker
    
        sudo apt-get -y install docker.io
      fi
    
      if ! which docker-compose; then
        echo "安装 docker-compose"
        sudo apt-get install -y -qq docker-compose
      fi
    }
    
    updateSourceList
    initDocker
    
    

    相关文章

      网友评论

          本文标题:docker安装脚本

          本文链接:https://www.haomeiwen.com/subject/lhnxmktx.html