安装docker,流程如下:

#bash install_docker.sh

#cat install_docker.sh
#!/usr/bin/env bash
#
BASE_DIR=$(dirname "$0")

function prepare_install() {
    yum install -y yum-utils device-mapper-persistent-data lvm2
}

function install_docker() {
    echo ">> Install Docker"
    prepare_install
    yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    rpm --import https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
    yum install -y docker-ce
}

function install_apt_docker() {
    echo ">> Install Docker"
    #prepare_install
    curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
    apt-key fingerprint 0EBFCD88
    src="deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian jessie stable"
    echo $src > /etc/apt/sources.list.d/docker.list
    apt update
    apt install -y docker-ce
}

function config_docker {
    mkdir -p /etc/docker/
    cp $BASE_DIR/docker/daemon.json /etc/docker/daemon.json
}

function start_docker {
    systemctl start docker
    systemctl enable docker
}

function main {
    which docker >/dev/null 2>&1
    if [ $? -ne 0 ];then
        install_docker
    fi
    if [ ! -f "/etc/docker/daemon.json" ]; then
        config_docker
    fi
    if [ ! "$(systemctl status docker | grep Active | grep running)" ]; then
        start_docker
    fi
}
main

注册地址配置如下:

#cat /etc/docker/daemon.json
{
    "registry-mirrors": ["https://bmtrgdvx.mirror.aliyuncs.com", "https://hub-mirror.c.163.com", "https://dockerhub.azk8s.cn"]
}

结尾

若对你有帮助,不介意赞赏一下

支付宝-zhifubao 微信-wechat
支付宝 支付宝