CentOS 8 安装Docker 报错requires container-selinux >= 2:2.x

什么是 Docker

简单来说,Docker 是一个开源的容器化平台,它可以让你:把应用程序和它所有的依赖打包到一个"容器"中运行。

在传统部署中,你可能遇到这样的问题:

"在我机器上能跑啊,怎么你那里就出错了?"

这通常是因为你们的环境(系统版本、依赖库、配置)不一致。

而 Docker 可以彻底解决这个问题。

安装 Docker

由于 Docker 官方并未给出安装教程,本文简单写一下 Docker Engine 的安装步骤:

安装 yum-utils

sudo yum install yum-utils -y

添加安装源到仓库

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

安装 Docker

sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

到目前为止都很成功,在安装的时候就开始各种环境报错。

报错如下:

xml 复制代码
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 2:49:56 ago on Wed 13 Aug 2025 10:59:48 AM CST.
Error:
 Problem 1: package docker-ce-3:26.1.3-1.el8.x86_64 from docker-ce-stable requires container-selinux >= 2:2.74, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package container-selinux-2:2.124.0-1.gitf958d0c.module+el8.5.0+681+c9a1951f.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.130.0-1.module+el8.5.0+770+e2f49861.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.189.0-1.module+el8.7.0+1152+ac778627.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.205.0-3.module+el8.9.0+1445+07728297.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.229.0-2.module+el8.10.0+1815+5fe7415e.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.229.0-2.module+el8.10.0+1825+623b0c20.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.229.0-2.module+el8.10.0+1843+6892ab28.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.229.0-2.module+el8.10.0+1872+2e18eb19.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.229.0-2.module+el8.10.0+1874+ce489889.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.229.0-2.module+el8.10.0+1880+8e896d1b.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.229.0-2.module+el8.10.0+1896+b18fa106.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.229.0-2.module+el8.10.0+1948+4b5cd4a9.noarch from appstream is filtered out by modular filtering
  - package container-selinux-2:2.229.0-2.module+el8.10.0+2001+6a33db9f.noarch from appstream is filtered out by modular filtering

这需要我们自行下载,我看网上都是国外的,但是我机器访问不到,幸好找到了国内的镜像版本,如果你缺少啥,就去这里下载:

https://mirrors.aliyun.com

执行以下命令即可:

sudo yum install https://mirrors.aliyun.com/centos/8-stream/AppStream/aarch64/os/Packages/container-selinux-2.167.0-1.module_el8.6.0+926+8bef8ae7.noarch.rpm

执行后,仍在报错,如下所示:

复制代码
Last metadata expiration check: 3:04:59 ago on Wed 13 Aug 2025 10:59:48 AM CST.
Error:
 Problem 1: package containerd.io-1.6.32-3.1.el8.x86_64 from docker-ce-stable conflicts with runc provided by runc-1:1.1.12-6.module+el8.10.0+2001+6a33db9f.x86_64 from @System
  - package containerd.io-1.6.32-3.1.el8.x86_64 from docker-ce-stable obsoletes runc provided by runc-1:1.1.12-6.module+el8.10.0+2001+6a33db9f.x86_64 from @System
  - package containers-common-2:1-82.module+el8.10.0+2001+6a33db9f.x86_64 from @System requires oci-runtime, but none of the providers can be installed
  - cannot install the best candidate for the job

我们执行强制执行命令,命令如下:

sudo dnf install -y --allowerasing docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

终于成功,效果如下:

太难了,期间看了stack overflow以及各种博客帖子还有问AI,一直找不到,基本都是centos 7的解决办法。不过最后总算完成了。

启动 Docker 服务

启动 Docker 服务,并设置自启动

sudo systemctl enable docker

验证 Docker

通过运行 hello-world 镜像验证 Docker Engine 安装是否成功

sudo docker run hello-world

看到以下效果基本就可以了。如图所示:

小结

本文介绍了 Docker 的基本概念及其在解决环境不一致问题中的作用,并详细记录了在 CentOS 8 系统上安装 Docker 时遇到的各种依赖冲突与报错问题。通过使用阿里云镜像和强制安装命令,最终成功完成了安装与验证。

相关推荐
光视界11 分钟前
从汞灯到 UV-LED:ALE 如何助力光刻机完成环保升级
经验分享
联蔚盘云16 分钟前
DevOps 正在从“交付工具”进化为企业级生产力引擎
经验分享
八十天环游世界6 小时前
财务自动化项目的ROI怎么测算?要看哪些指标?
经验分享
网安小学生(兼顾数据库版)6 小时前
艾体宝 TrueFoundry 如何让企业 AI 工具集成避免 “孤岛化“?
经验分享·艾体宝·艾体宝it·艾体宝truefoundry
聪明的笨猪猪20 小时前
企业知识库AI架构选型:落地导向的架构决策与组件清单
经验分享·面试·架构·embedding·数据库架构
Go Work1 天前
两个等值条件摆着,MySQL 偏要全表扫
经验分享·笔记
深圳智根网络程序开发1 天前
WordPress固定链接怎么设?改不对谷歌收录直接崩
经验分享
德思特1 天前
如何提升 5G 移动性切换验证效率?德思特 Amarisoft Callbox 新增 NR SA LTM 测试功能详解
经验分享·无线通信·车载通信
虹科数字化与AR1 天前
农业机械AR质检ROI怎么算?从搬运、测量、返工和交付成本入手
经验分享·ar·质检·农业机械
聪明的笨猪猪2 天前
Java 工程案例:AI 生成 @Async 异步线程池踩坑
java·经验分享·面试·ai编程