参考:
https://blog.csdn.net/u014646662/article/details/104982223/
https://blog.csdn.net/m0_59196543/article/details/124749175
1、卸载原有或者以前安装的docker
如果之前安装过旧版本的Docker,可以使用下面命令卸载:
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine \
docker-ce
2、安装docker
1)docker所依赖的包环境
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2 --skip-broken
2)设置Docker-ce 阿里源镜像
# 设置Docker-ce 阿里源镜像
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
也可以使用官方的,不过比较慢
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
更新一下yum软件包
yum makecache fast
3)安装docker
yum install -y docker-ce
4)启动docker
systemctl start docker # 启动docker服务
systemctl stop docker # 停止docker服务
systemctl restart docker # 重启docker服务
查看docker的运行状态
systemctl status docker
5)开机启动docker
systemctl enable docker.service
3、配置镜像加速
docker官方镜像仓库网速较差,我们需要设置国内镜像服务:
参考阿里云的镜像加速文档:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://itd6uilt.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker