一键部署docker

2023-08-02  本文已影响0人  平凡的运维之路

shell 一键部署docker

#! /bin/bash
#One click deployment Docker

remove_old_docker(){
    echo "yum remove docker old version"
    yum remove docker \
             docker-client \
             docker-client-latest \
             docker-common \
             docker-latest \
             docker-latest-logrotate \
             docker-logrotate \
             docker-engine
}

init_install_docker(){
    sudo yum install -y yum-utils device-mapper-persistent-data lvm2
     
    sudo yum-config-manager --add-repo \
       https://download.docker.com/linux/centos/docker-ce.repo

    yum -y install docker-ce docker-ce-cli containerd.io
    
    base_docker_env
}

base_docker_env(){
    systemctl start docker && systemctl enable docker
     
    docker version 
      
    sudo systemctl daemon-reload
    sudo systemctl restart docker

    sudo mkdir -p /etc/docker
    sudo tee /etc/docker/daemon.json <<-'EOF'
    {
     "registry-mirrors": ["https://onl4ynrr.mirror.aliyuncs.com"]
    }
    EOF
    
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
}

init_install_select_docker_version(){
    sudo yum install -y yum-utils device-mapper-persistent-data lvm2
     
    sudo yum-config-manager --add-repo \
       https://download.docker.com/linux/centos/docker-ce.repo
     
    yum list docker-ce --showduplicates | sort -r
     
    yum -y install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
    
    base_docker_env
}

remove_old_docker

init_install_docker
上一篇下一篇

猜你喜欢

热点阅读