如果之前安装过旧版本的Docker,可以使用下面命令卸载:
[root@web1 ~]# 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
安装docker
首先需要虚拟机联网,安装yum工具
[root@web1 ~]# yum install -y yum-utils \
device-mapper-persistent-data \
lvm2 --skip-broken
然后更新本地镜像源:
# 设置docker镜像源
[root@web1 ~]# yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@web1 ~]# sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
[root@web1 ~]# yum makecache fast
最后安装docker
[root@web2 ~]# yum install -y docker-ce
启动docker
Docker应用需要用到各种端口,逐一去修改防火墙设置。非常麻烦,因此需要直接关闭防火墙!
# 关闭
[root@web1 ~]# systemctl stop firewalld
# 禁止开机启动防火墙
[root@web1 ~]# systemctl disable firewalld
查看docker是否启动
[root@web1 ~]# docker images
通过命令启动docker
[root@web1 ~]# systemctl start docker # 启动docker服务
[root@web1 ~]# systemctl stop docker # 停止docker服务
[root@web1 ~]# systemctl restart docker # 重启docker服务
如果启动时出现错误:
提示:Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
前往此网站浏览报错信息并修改:
CentOS安装Docker(超详细)_centos 安装docker-CSDN博客
https://cn.bing.com/search?pglt=41&q=CentOS%E5%AE%89%E8%A3%85Docker(%E8%B6%85%E8%AF%A6%E7%BB%86)_centos+%E5%AE%89%E8%A3%85docker-CSDN%E5%8D%9A%E5%AE%A2&cvid=c2af4037cd1443e3b0ef6b5c0a59162d&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQABhAMgYIAhAAGEAyBggDEAAYQDIGCAQQABhAMgYIBRAAGEAyBggGEAAYQDIGCAcQABhAMgYICBBFGEHSAQgxMjM1ajBqMagCCLACAQ&FORM=ANNTA1&ucpdpc=UCPD&PC=ASTS
安装docker出现错误:
需要:container-selinux >= 2:2.74
slirp4netns >= 0.4
fuse-overlayfs >= 0.7
container-selinux >= 2:2.74

[root@web1 ~]# yum install docker-ce docker-ce-cli containerd.io
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.6.33-3.1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 containerd.io-1.6.33-3.1.el7.x86_64 需要
---> 软件包 docker-ce.x86_64.3.26.1.4-1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 3:docker-ce-26.1.4-1.el7.x86_64 需要
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-26.1.4-1.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.26.1.4-1.el7 将被 安装
--> 正在处理依赖关系 docker-buildx-plugin,它被软件包 1:docker-ce-cli-26.1.4-1.el7.x86_64 需要
--> 正在处理依赖关系 docker-compose-plugin,它被软件包 1:docker-ce-cli-26.1.4-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.6.33-3.1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 containerd.io-1.6.33-3.1.el7.x86_64 需要
---> 软件包 docker-buildx-plugin.x86_64.0.0.14.1-1.el7 将被 安装
---> 软件包 docker-ce.x86_64.3.26.1.4-1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 3:docker-ce-26.1.4-1.el7.x86_64 需要
---> 软件包 docker-ce-rootless-extras.x86_64.0.26.1.4-1.el7 将被 安装
--> 正在处理依赖关系 fuse-overlayfs >= 0.7,它被软件包 docker-ce-rootless-extras-26.1.4-1.el7.x86_64 需要
--> 正在处理依赖关系 slirp4netns >= 0.4,它被软件包 docker-ce-rootless-extras-26.1.4-1.el7.x86_64 需要
---> 软件包 docker-compose-plugin.x86_64.0.2.27.1-1.el7 将被 安装
--> 解决依赖关系完成
错误:软件包:3:docker-ce-26.1.4-1.el7.x86_64 (docker-ce-stable)
需要:container-selinux >= 2:2.74
错误:软件包:docker-ce-rootless-extras-26.1.4-1.el7.x86_64 (docker-ce-stable)
需要:slirp4netns >= 0.4
错误:软件包:docker-ce-rootless-extras-26.1.4-1.el7.x86_64 (docker-ce-stable)
需要:fuse-overlayfs >= 0.7
错误:软件包:containerd.io-1.6.33-3.1.el7.x86_64 (docker-ce-stable)
需要:container-selinux >= 2:2.74
您可以尝试添加 --skip-broken 选项来解决该问题
您可以尝试执行:rpm -Va --nofiles --nodigest
解决办法:安装【docker-ce-selinux】
[root@web1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
安装完毕后再次执行,成功
[root@web1 ~]# yum install docker-ce docker-ce-cli containerd.io
1.el7.x86_64 7/10
验证中 : 1:docker-ce-cli-26.1.4-1.el7.x86_64 8/10
验证中 : docker-ce-rootless-extras-26.1.4-1.el7.x86_64 9/10
验证中 : docker-buildx-plugin-0.14.1-1.el7.x86_64 10/10
已安装:
docker-ce.x86_64 3:26.1.4-1.el7
作为依赖被安装:
container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.6.33-3.1.el7
docker-buildx-plugin.x86_64 0:0.14.1-1.el7 docker-ce-cli.x86_64 1:26.1.4-1.el7
docker-ce-rootless-extras.x86_64 0:26.1.4-1.el7 docker-compose-plugin.x86_64 0:2.27.1-1.el7
fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7
slirp4netns.x86_64 0:0.4.3-4.el7_8
完毕!
[root@web1 ~]# docker -v
Docker version 26.1.4, build 5650f9b