参考官网:https://docs.docker.com/engine/install/centos/
查看linux版本
uname -r
3.10.0-1160.53.1.el7.x86_64
确保返回版本是3.10及以上
更新centos包
yum update
删除旧版本docker
可能不需要
yum remove docker docker-common docker-selinux docker-engine
安装工具包和依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
配置docker仓库
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(中央仓库)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里仓库)
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
查看可用的docker版本
yum list docker-ce --showduplicates | sort -r
安装
可以安装最新版本或指定版本安装
1、安装最新版本
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
2、指定版本安装
版本号为:docker-ce加上冒号后边的开始,到-结束的部分。如( docker-ce-18.09.1)
Install a specific version by its fully qualified package name, which is the package name (docker-ce) plus the version string (2nd column) starting at the first colon ( : ), up to the first hyphen, separated by a hyphen (-). For example, docker-ce-18.09.1
yum -y install docker-ce-18.03.1.ce
启动
systemctl start docker
systemctl enable docker 设置开机自启
systemctl start docker
systemctl enable docker
查看版本
docker version