今天Docker新搞了一个CentOS镜像,在运行基于该镜像的容器,执行yum命令时,遇到了如下报错:

[root@GC Administrator]# yum install -y yum-utils
Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream                                                               41  B/s |  38  B     00:00
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

目前使用 docker pull centos 不指定tag,拉取的latest,centos的版本为 8.4.2105

[root@GC Administrator]# cat /etc/redhat-release 
CentOS Linux release 8.4.2105

1. yum镜像源问题

其中 Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist 是yum镜像源的问题,这个问题我在之前的一篇文章中已经总结过解决方案。
CentOS 执行yum命令报错【错误:为仓库 ‘appstream‘ 下载元数据失败: …】

你可以参考上述文章进行解决,你也可以直接运行下面的命令进行解决(上述文章中提到的其中一种方案)

# Centos 8 之前版本
# 以 CentOS 7.9.2009 为例
minorver=7.9.2009
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
         -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo

# CentOS 8 版本
# 以 CentOS 8.5.2111 为例
minorver=8.5.2111
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
         -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo

2. 语言环境问题

其中Failed to set locale, defaulting to C.UTF-8是系统语言环境问题
下面是解决方案:

1)查看本地安装的语言包

[root@GC ~]# locale -a
C
C.utf8
POSIX

2)安装语言包

安装中文语言包:yum install glibc-langpack-zh
安装英文语言包:yum install glibc-langpack-en

我这里只安装了 中文语言包 👇

[root@GC Administrator]# locale -a
C
C.utf8
POSIX
zh_CN
zh_CN.gb18030
zh_CN.gbk
zh_CN.utf8
zh_HK
zh_HK.utf8
zh_SG
zh_SG.gbk
zh_SG.utf8
zh_TW
zh_TW.euctw
zh_TW.utf8

3)设置语言环境

echo "export LC_ALL=zh_CN.utf8" >> /etc/profile
source /etc/profile

从你已安装的语言中,选择你想要设置的语言,我这里选择的是zh_CN.utf8

4)验证语言是否设置成功

[root@GC Administrator]# yum install -y yum-utils
Last metadata expiration check: 0:17:50 ago on 2023年08月25日 星期五 14时06分57秒.
Dependencies resolved.
========================================================================================================================
 Package                                 Architecture          Version                      Repository             Size
========================================================================================================================
Installing:
 yum-utils                               noarch                4.0.18-4.el8                 baseos                 71 k
Installing dependencies:
 dbus-glib                               x86_64                0.110-2.el8                  baseos                127 k
 dnf-plugins-core                        noarch                4.0.18-4.el8                 baseos                 69 k
 python3-dateutil                        noarch                1:2.6.1-6.el8                baseos                251 k
 python3-dbus                            x86_64                1.2.4-15.el8                 baseos                134 k
 python3-dnf-plugins-core                noarch                4.0.18-4.el8                 baseos                234 k
 python3-six                             noarch                1.11.0-8.el8                 baseos                 38 k

Transaction Summary
========================================================================================================================
Install  7 Packages

Total download size: 925 k
Installed size: 2.3 M
Downloading Packages:
(1/7): dnf-plugins-core-4.0.18-4.el8.noarch.rpm                                         145 kB/s |  69 kB     00:00
(2/7): dbus-glib-0.110-2.el8.x86_64.rpm                                                 256 kB/s | 127 kB     00:00
(3/7): python3-dateutil-2.6.1-6.el8.noarch.rpm                                          363 kB/s | 251 kB     00:00
(4/7): python3-dbus-1.2.4-15.el8.x86_64.rpm                                             404 kB/s | 134 kB     00:00
(5/7): python3-six-1.11.0-8.el8.noarch.rpm                                              225 kB/s |  38 kB     00:00
(6/7): python3-dnf-plugins-core-4.0.18-4.el8.noarch.rpm                                 536 kB/s | 234 kB     00:00
(7/7): yum-utils-4.0.18-4.el8.noarch.rpm                                                299 kB/s |  71 kB     00:00
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   879 kB/s | 925 kB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                1/1
  Installing       : python3-six-1.11.0-8.el8.noarch                                                                1/7
  Installing       : python3-dateutil-1:2.6.1-6.el8.noarch                                                          2/7
  Installing       : dbus-glib-0.110-2.el8.x86_64                                                                   3/7
  Running scriptlet: dbus-glib-0.110-2.el8.x86_64                                                                   3/7
  Installing       : python3-dbus-1.2.4-15.el8.x86_64                                                               4/7
  Installing       : python3-dnf-plugins-core-4.0.18-4.el8.noarch                                                   5/7
  Installing       : dnf-plugins-core-4.0.18-4.el8.noarch                                                           6/7
  Installing       : yum-utils-4.0.18-4.el8.noarch                                                                  7/7
  Running scriptlet: yum-utils-4.0.18-4.el8.noarch                                                                  7/7
  Verifying        : dbus-glib-0.110-2.el8.x86_64                                                                   1/7
  Verifying        : dnf-plugins-core-4.0.18-4.el8.noarch                                                           2/7
  Verifying        : python3-dateutil-1:2.6.1-6.el8.noarch                                                          3/7
  Verifying        : python3-dbus-1.2.4-15.el8.x86_64                                                               4/7
  Verifying        : python3-dnf-plugins-core-4.0.18-4.el8.noarch                                                   5/7
  Verifying        : python3-six-1.11.0-8.el8.noarch                                                                6/7
  Verifying        : yum-utils-4.0.18-4.el8.noarch                                                                  7/7

Installed:
  dbus-glib-0.110-2.el8.x86_64      dnf-plugins-core-4.0.18-4.el8.noarch          python3-dateutil-1:2.6.1-6.el8.noarch
  python3-dbus-1.2.4-15.el8.x86_64  python3-dnf-plugins-core-4.0.18-4.el8.noarch  python3-six-1.11.0-8.el8.noarch
  yum-utils-4.0.18-4.el8.noarch

Complete!

OK,搞定~

Logo

纵情码海钱塘涌,杭州开发者创新动! 属于杭州的开发者社区!致力于为杭州地区的开发者提供学习、合作和成长的机会;同时也为企业交流招聘提供舞台!

更多推荐