参考官方文档:
https://docs.docker.com/engine/install/centos/

1、安装yum源

sudo yum install -y yum-utils

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

2、安装最新版docker

sudo yum install docker-ce docker-ce-cli containerd.io

3、安装指定版本docker

yum list docker-ce --showduplicates | sort -r

# 例如 18.09.1
sudo yum install docker-ce-18.09.1 docker-ce-cli-18.09.1 containerd.io

4、配置 docker

vi /etc/docker/daemon.json
{
	"insecure-registries": [],
	"registry-mirrors": ["https://gug8awv5.mirror.aliyuncs.com"],
	"exec-opts": ["native.cgroupdriver=cgroupfs"],
	"storage-driver": "overlay2",
	"storage-opts": [
		"overlay2.override_kernel_check=true",
		"overlay2.size=10G"
	],
	"metrics-addr": "0.0.0.0:9323 ",
	"experimental": true,
	"log-driver": "json-file",
	"log-opts": {
		"max-size": "20m",
		"max-file": "10"
	}
}

{
    "insecure-registries": [], # 非https的镜像仓库
    # 配置镜像加速器,实测清华北大中科大都不行,还是阿里云快
    # https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 登录查看自己专属的加速地址
    "registry-mirrors":["https://xxxxxxxxx.mirror.aliyuncs.com"]
    "graph": "/var/lib/docker",
    "exec-opts": ["native.cgroupdriver=cgroupfs"],
    "storage-driver": "overlay2",
    "storage-opts": [  # 配置 overlay2 驱动的单个容器磁盘限制
      "overlay2.override_kernel_check=true",
      "overlay2.size=10G"
    ],
    "metrics-addr": “0.0.0.0:9323",
    "experimental": true,
    "log-driver": "json-file",
    "log-opts":
    {
        "max-size": "20m",
        "max-file": "10"
    }
}

# 重启docker
systemctl daemon-reload
systemctl enable docker
systemctl restart docker