Dockerfile中 RUN yum -y install vim失敗Cannot prepare internal mirrorlist: No URLs in mirrorlist


隱秘的版本問題————

Dockerfile中 RUN yum -y install vim失敗Cannot prepare internal mirrorlist: No URLs in mirrorlist


目錄:

  • 寫在前面:心得+本文精華(本文該問題的思考解決方式)

  • 寫在后面:為解決本文該問題----我的折騰


? 心得+本文精華(本文該問題的思考解決方式)

? 心得:修改文件,記得備份!尤其是配置文件

? 本文該問題的思考解決方式:實際上就是開發(fā)中遇到的版本問題



一、問題

1、系統(tǒng)版本:linux版本centos7.6(1080)


2、錯誤背景:我想要自定義tomcat環(huán)境鏡像,通過build Dockerfile的方式

  • Dockerfile 文件內(nèi)容如下:
FROM centos
MAINTAINER ylb<11>

ADD jdk-8u301-linux-aarch64.tar.gz /usr/local/
ADD apache-tomcat-9.0.62.tar.gz /usr/local/

RUN yum -y install vim

ENV MYPATH /usr/local/
WORKDIR $MYPATH

ENV JAVA_HOME /usr/local/jdk1.8.0_301
ENV CLASSPATH $JAVA_HOME/lib/
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.62
ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.62
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$CATALINA_HOME/lib

EXPOSE 8080

CMD /usr/local/apache-tomcat-9.0.62/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.62/logs/catalina.out


3、錯誤發(fā)生:執(zhí)行到RUN yum -y install vim就報錯,Cannot prepare internal mirrorlist: No URLs in mirrorlist

圖片.png


4、錯誤原因:

究其根因是版本問題

  • 學(xué)習(xí)docker的視頻,我跟著狂神的視頻,為了減少錯誤,我選擇和他系統(tǒng)保持一致,安裝的軟件、鏡像、容器的版本等等(涉及到版本的)都保持一致
  • 但是,問題在于,狂神的視頻發(fā)布的時間和現(xiàn)在不同,視頻的last版本,是他當(dāng)時的last
    • 大白話就是,狂神當(dāng)時(last)最新的centos版本是7.xx,而現(xiàn)在(last)最新的版本的centos是8.xxx

出現(xiàn)版本原因的還有yum

  • 伴隨著不同centos版本所兼容的yum,它的內(nèi)容是不同的
    • 舉例:Centos-vault-6.10.repo 和 Centos-vault-8.5.2111.repo的對比:發(fā)現(xiàn)版本6的內(nèi)容比較少,它相對于8的話,沒有[centosplus]、[PowerTools]、[AppStream]

    • 最最重要的是:本次問題報錯所沒有AppStream,而這個AppStream是版本8的centos才有的,是版本8的新增內(nèi)容,在版本7是沒有它的,官網(wǎng)沒有提供!


? 認(rèn)識到版本的重要性了吧,內(nèi)容的增刪改!



二、正確解決方式

方式1:升級centos系統(tǒng)為版本8的,然后再使用build Dockerfile

方式2:涉及到centos版本的地方,指明版本,如本文問題核心Dockerfile中的 FROM centos:7

  • 指定dockerfile的centos版本



三、為什么我知道"這個AppStream是版本8的centos才有的,是版本8的新增內(nèi)容,在版本7是沒有它的,官網(wǎng)沒有提供"

1、線索1:搜索問題"Cannot prepare internal mirrorlist: No URLs in mirrorlist"

發(fā)現(xiàn):

  • 解釋了問題原因:

在2022年1月31日,CentOS團隊終于從官方鏡像中移除CentOS 8的所有包。

CentOS 8已于2021年12月31日壽終正非,但軟件包仍在官方鏡像上保留了一段時間?,F(xiàn)在他們被轉(zhuǎn)移到https://vault.centos.org


2、線索2:

跟著解決方案的文章,發(fā)現(xiàn):

  • 鏡像和倉庫:阿里、騰訊、中科院

http://mirrors.ustc.edu.cn/help/centos.html

https://mirrors.aliyun.com/repo/

https://mirrors.cloud.tencent.com/repo/


忽然發(fā)現(xiàn),哦,原來7是真的沒有appstream


補充:看文章的時候,注意文章涉及到鏈接的地方,版本、版本、版本!

1)有時候文章提供了解決方法,但是版本和咱對不上,怎么辦?

  • 去掉一些參數(shù),自己進入網(wǎng)站挑選合適自己的版本的

2)舉例:搜索No URLs in mirrorlist error,找到某一篇文章,他提供了一種解決方案:

圖片.png

3)提取鏈接到瀏覽器,把版本對應(yīng)不上的參數(shù)去掉,得到:

https://mirrors.aliyun.com/repo/


3、線索3:搜索問題的時候,就算我輸入centos7,特意強調(diào)了centos 版本是7

發(fā)現(xiàn):

  • 搜索出來的版本都是8的,這個是一個提示點




? 為解決本文該問題----我的折騰

  • 結(jié)果是無效折騰

1、錯誤原因:

  • 搜索得知錯誤原因,看到了centos版本是8,以為是所有的版本都一樣,然后,將別人文章centos版本8版本,直接改成7,以為就完美解決問題

在2022年1月31日,CentOS團隊終于從官方鏡像中移除CentOS 8的所有包。

CentOS 8已于2021年12月31日壽終正非,但軟件包仍在官方鏡像上保留了一段時間?,F(xiàn)在他們被轉(zhuǎn)移到https://vault.centos.org


2、將別人文章centos版本8版本,直接改成7,以為就完美解決問題

1、錯誤:

CentOS Linux 8 - AppStream                       21  B/s |  38  B     00:01    
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
The command '/bin/sh -c yum -y install vim' returned a non-zero code: 1

2、解決手段:

① 如果你仍然需要運行你的舊CentOS 8,你可以在/etc/yum.repos中更新repos.d使用vault.centos.org代替mirror.centos.org。

cd /etc/yum.repos.d
vi CentOS-AppStream.repo
[appstream]
name=CentOS $releasever - AppStream
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/AppStream/$basearch/os/
baseurl=https://vault.centos.org/centos/$releasever/AppStream/$basearch/os/ 
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

② 執(zhí)行命令:

yum clean all
yum makecache


2-2、又發(fā)生錯誤:

https://vault.centos.org/centos/7/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found

Determining fastest mirrors
https://vault.centos.org/centos/7/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article 

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 (CentOS Linux 7 - AppStream),
 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=appstream ...

     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 appstream
        or
            subscription-manager repos --disable=appstream

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=appstream.skip_if_unavailable=true

failure: repodata/repomd.xml from appstream: [Errno 256] No more mirrors to try.
https://vault.centos.org/centos/7/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found


2-2、錯誤原因:

  • 是因為yum已經(jīng)更新了的原因?qū)е碌?http://mirrors.163.com/centos/ 進官網(wǎng)可以看到已經(jīng)更新到7.x了
    打開CentOS7-Base.repo(名字可能不一樣),一般在 ./etc/yum.repos.d文件夾下
vim /etc/yum.repos.d/CentOS7-Base.repo
# 將其中baseurl中的$releasever全改為7

2-2、解決手段:

  • 解決阿里云CentOS7 yum安裝appstream報錯,更新yum后無法makecache的問題
  • 將/etc/yum.repos.d/CentOS-AppStream.repo,替換為如下:
[appstream]
name=CentOS-$releasever
baseurl=http://mirrors.aliyun.com/centos/$releasever/appstream/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7


3、解決無效,嘗試其他解決方案:

(1)方式一:測試無效
圖片.png
(2)方式二:測試也無效

1)將源文件備份

cd /etc/yum.repos.d/ && mkdir backup && mv *repo backup/

2)下載阿里源文件

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3)更新源里面的地址

sed -i -e "s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-*
sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*

4)生成緩存

yum clean all && yum makecache


3-2、又報錯

  • 問題是:執(zhí)行第四步yum clean all && yum makecache報錯:failure: repodata/repomd.xml from AppStream: [Errno 256] No more mirrors to try.
One of the configured repositories failed (CentOS-7-stream - AppStream - mirrors.aliyun.com),
 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=AppStream ...

     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 AppStream
        or
            subscription-manager repos --disable=AppStream

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=AppStream.skip_if_unavailable=true

failure: repodata/repomd.xml from AppStream: [Errno 256] No more mirrors to try.
http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30000 milliseconds')
https://mirrors.aliyun.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
http://mirrors.aliyun.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30000 milliseconds')
http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
[root@iZwz9535z41cmgcpkm7i81Z yum.repos.d]# 


3-2、錯誤原因是:在于yum源問題

3-2、解決手段:解決yum源問題

1)查看centos系統(tǒng)本身所安裝的yum依賴包

rpm -qa|grep yum
圖片.png

2)卸載這些軟件包 rpm -e xx --nodeps


圖片.png
  1. 進入centos鏡像網(wǎng)站找到自己對應(yīng)系統(tǒng)需要的yum包
  • 查看系統(tǒng)的命令:
 cat /etc/redhat-release
  • 查看系統(tǒng)的位數(shù):
file /bin/ls
  1. 下載yum依賴包:
  • 網(wǎng)站:https://vault.centos.org/
  • 找到對應(yīng)版本的os/x86_64/Packages/
  • 分別下載[注意:我的linux版本是centos7.6(1080)]
wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm

wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm

wget https://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-3.4.3-1①61.el7.centos.noarch.rpm

5)安裝yum依賴包

rpm -ivh yum-*

6)更換CentOS-Base.repo

① 進入 /etc/yum.repos.d,先備份

cd /etc/
cd yum.repos.d
# 備份一下:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

② 進入官網(wǎng):http://mirrors.ustc.edu.cn/help/centos.html

圖片.png
  • 自己先建立一個txt文件,內(nèi)容拷貝進去后,修改名稱為CentOS-Base.repo
  • 使用工具xftp,將CentOS-Base.repo 傳輸?shù)?etc/yum.repos.d目錄
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

③ 執(zhí)行命令:

yum clean all
yum makecache



還報錯,你以為到這里,我就放棄了嗎?

---yes, 我的貪吃蛇已經(jīng)快排名第一了哈哈哈

  • 繼續(xù)解決~~~


二、繼續(xù)我的不正確解決手段:

哇塞,玩完貪吃蛇的我,不一樣了,眼睛不一樣了,一瞅,立馬發(fā)現(xiàn)了,自己的centos的配置文件下的yum.repos.d/目錄下的文件和別人不同

  • 發(fā)現(xiàn)缺少文件了

1、再搜索問題,發(fā)現(xiàn)缺少文件了

"將/etc/yum.repos.d/目錄下的CentOS-Base.repo、CentOS-AppStream.repo、CentOS-Extras.repo中的mirrorlist注釋掉,將baseurl 修改為阿里源......"

圖片.png


2、解決方式1【結(jié)果悲捶了,只剩下一個Centos-Base.repo文件了-----說明了備份的重要性】:

將/etc/yum.repos.d 清空后,重新下載

# 刪除yum.repos.d目錄下所有文件
rm -f /etc/yum.repos.d/*
# 然后重新下載阿里的源(確保網(wǎng)絡(luò)連接)--注意版本哦,我的centos是7的版本
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 清理緩存
yum clean all


? 心得:修改文件,記得備份!

● 所以,咱沒備份,配置文件全沒了,咱重置一下系統(tǒng)吧


? 重置Linux系統(tǒng)

  • 在阿里云官網(wǎng)上找到你購買的那個服務(wù)器,點一下重置系統(tǒng),選擇centos7,然后重置一下密碼


1、重置系統(tǒng)過后、發(fā)現(xiàn)/etc/yum.repos.d/目錄下:

  • CentOS-Base.repo
  • epel.repo
圖片.png


2、重新安裝docker、配置阿里云鏡像加速

(1)安裝

# 1、卸載舊版本:
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
 # 2、使用倉庫安裝
 # 需要的安裝包
 sudo yum install -y yum-utils   
 # 設(shè)置倉庫【默認(rèn)是國外的,我們不要使用國外的,需要使用國內(nèi)的阿里云鏡像地址】
   sudo yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
# 更新yum 軟件包索引    
yum makecache fast
    
    
# 3、安裝 Docker 引擎   docker-ce 社區(qū)  docker-ee 企業(yè)版
 yum install docker-ce docker-ce-cli containerd.io

 # 4、啟動 Docker
 systemctl start docker
 
 # 檢查是否成功啟動
 docker version
 
 # 5、測試hello-world 
 docker run hello-world
 
 # 查看下載的鏡像
 docker images


3、阿里云鏡像加速

(1)登錄阿里云官網(wǎng),點擊控制臺,找到產(chǎn)品與服務(wù),搜容器鏡像服務(wù)

圖片.png
  • 鏡像加速器:
圖片.png

(2)配置使用:

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://o10wzpax.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

● 發(fā)現(xiàn)/etc/yum.repos.d/目錄下:

  • CentOS-Base.repo
  • docker-ce.repo
  • epel.repo
  • epel.repo.rpmnew
  • epel-testing.repo
圖片.png




三、錯誤依舊

折騰累了,貪吃蛇也玩得手指起泡了,突然這次又火眼金睛,發(fā)現(xiàn)了阿里、騰訊鏡像中,好奇對比一下centos7—Base.repo 和 centos8—Base.repo,

還有,之前搜索發(fā)現(xiàn):CentOS團隊終于從官方鏡像中移除CentOS 8的所有包。

CentOS 8已于2021年12月31日壽終正非,但軟件包仍在官方鏡像上保留了一段時間?,F(xiàn)在他們被轉(zhuǎn)移到https://vault.centos.org

順便對比一下:Centos-vault-6.10.repo 和 Centos-vault-8.5.2111.repo (因為沒有版本7的,所以找6的來對比)

  • 恍惚之間,想到了時間是一把殺豬刀,現(xiàn)在是2022年了,而我的學(xué)習(xí)視頻,狂神的Docker最新超詳細(xì)版教程通俗易懂視頻,是2020年的

    • 在下版本,有何貴干!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容