Docker安装失败 (CentOs上)亲测可用

给公司的新电脑配置环境,安装完CentOs后,一直装不上docker

报错如下:

base                                                                                                                                                                  | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                      | 3.5 kB  00:00:00     
https://yum.dockerproject.org/repo/main/centos/7/repodata/repomd.xml: [Errno 14] curl#60 - "Issuer certificate is invalid."
Trying other mirror.
It was impossible to connect to the CentOS servers.
This could mean a connectivity issue in your environment, such as the requirement to configure a proxy,
or a transparent proxy that tampers with TLS security, or an incorrect system clock.
You can try to solve this issue by using the instructions on https://wiki.centos.org/yum-errors
If above article doesn't help to resolve this issue please use https://bugs.centos.org/.



 One of the configured repositories failed (Docker Repository),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=dockerrepo ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable dockerrepo
        or
            subscription-manager repos --disable=dockerrepo

     5. Configure the failing repository to be skipped, if

一开始以为是网不好,就下在国内的镜像,但是还是不行。
后面发现“ yum doesn’t have enough cached data to continue”,按着这个找果然找到解决方法:如下

//备份
mv /etc/yum.repos.d /etc/yum.repos.d.bak

//创建源目录
mkdir /etc/yum.repos.d

//下载阿里云yum配置
wget -0 /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

//清理缓存
yum clean all

//建缓存
yum makecache

//执行,无报错继续往下
yum update

//更新索引
yum makecache fast

//按着docker社区,企业版
yum install docker-ce docker ce-cli containerd.io

//启动docker
systemctl start docker 

//查看镜像
docker images
### 解决CentOS系统中Docker安装失败的问题 当在CentOS上遇到Docker安装失败的情况时,可以按照以下方法排查并解决问题。 #### 清理YUM缓存 如果之前尝试过安装Docker但未成功,残留的数据可能导致新的安装出现问题。建议先清理所有的yum缓存: ```bash sudo yum clean all ``` 这一步骤有助于清除旧的元数据和其他可能干扰新版本安装的信息[^1]。 #### 安装必要的依赖项 确保系统已经更新到最新状态,并安装一些基本工具来支持后续操作: ```bash sudo yum update -y sudo yum install -y yum-utils device-mapper-persistent-data lvm2 ``` 这些命令不仅会升级现有的软件包,还会安装用于管理存储设备所需的组件[^2]。 #### 设置阿里云源加速下载速度 为了提高下载效率以及减少因网络原因造成的错误,推荐配置国内镜像源作为默认仓库地址之一: ```bash curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo ``` 该命令将官方库替换为中国境内的快速访问节点,从而加快文件传输速率。 #### 添加稳定版Docker CE仓库 接着添加一个由Docker官方维护的安全且稳定的社区版(CE)储存库: ```bash sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo ``` 此步骤允许从指定位置获取最新的二进制分发包,而不是仅限于本地可用资源[^3]。 #### 正式安装Docker引擎及相关组件 现在执行实际的安装过程,包括核心服务端和服务客户端两部分: ```bash sudo yum install docker-ce docker-ce-cli containerd.io ``` 这里指定了要安装的具体项目名称及其关联模块,以确保获得完整的环境设置。 #### 启动与启用Docker守护进程 完成上述准备工作之后,就可以正式启动Docker服务了;同时将其设为开机自启项以便长期保持在线工作模式: ```bash sudo systemctl start docker sudo systemctl enable docker ``` 这两条指令分别负责立即激活当前实例和注册定时任务计划,在每次重启计算机后自动恢复运行状况。 #### 安装成果 最后可以通过拉取试容器映像的方式检验整个流程是否顺利完成: ```bash docker run hello-world ``` 这条简单的命令将会展示一段欢迎消息,证明Docker能够正常运作并且具备联网能力去检索远程资料。 #### 处理潜在问题 对于某些情况下仍然存在连接超时或者其他异常现象,则考虑调整`/etc/docker/daemon.json`中的代理服务器列表,加入更多可靠的镜像站点选项,如下所示: ```json { "registry-mirrors": [ "https://docker.m.daocloud.io", "https://dockerproxy.com" ] } ``` 修改完成后记得重新加载配置文件使更改生效: ```bash sudo systemctl daemon-reload sudo systemctl restart docker ``` 这样做的目的是优化请求路径,绕过可能出现瓶颈的地方,进而提升整体性能表现[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值