2022年 Centos8停止维护 替换阿里源 No URLs in mirrorlist 问题 Dockerfile 打包无法使用yum install 问题

CentOS8停止维护后, 无法使用yum安装软件, 报错等等.

如:

Failed to download metadata for repo 'AppStream'
Error: Failed to download metadata for repo 'AppStream'

或者

Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: No URLs in mirrorlist.

等等.

解决方法

替换yum源

  1. 进入源目录, 备份源文件
cd /etc/yum.repos.d/
mkdir backup && mv *repo backup/
  1. 安装阿里云源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  1. 非ECS服务器则 修改源文件, 防止出现Couldn’t resolve host 'mirrors.cloud.aliyuncs.com 报错问题
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

详见阿里云文档, https://help.aliyun.com/document_detail/405635.html?spm=5176.smartservice_service_chat.0.0.712c3f1bBoZ19I
4. 生成缓存

yum makecache
问题解决

DockerFile 容器内 CentOS8 yum源 No URLs in mirrorlist问题处理, 方法同上.

dockerfile文件 添加

# CentOS-8 yum源问题处理
# 删除旧配置
RUN rm -rf /etc/yum.repos.d/*.repo
# 安装源
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# 解决源出现 Couldn't resolve host 'mirrors.cloud.aliyuncs.com' 问题
RUN sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
# 生成缓存
RUN yum makecache
# 安装
RUN yum -y install xxx(需要安装的软件)
问题解决

你可能感兴趣的:(Docker,服务器及部署,服务器,centos,阿里云,centos8,docker)