【在下版本,有何貴幹?】Dockerfile中 RUN yum -y install vim失敗Cannot prepare internal mirrorlist: No URLs in mirrorlist
- 2022 年 4 月 23 日
- 筆記
- 【在下版本,有何貴幹?】
隱秘的版本問題————
Dockerfile中 RUN yum -y install vim失敗Cannot prepare internal mirrorlist: No URLs in mirrorlist
目錄:
寫在前面:心得+本文精華(本文該問題的思考解決方式)
寫在後面:為解決本文該問題—-我的折騰
☺ 心得+本文精華(本文該問題的思考解決方式)
♡ 心得:修改文件,記得備份!尤其是配置文件
♡ 本文該問題的思考解決方式:實際上就是開發中遇到的版本問題
一、問題
1、系統版本:linux版本centos7.6(1080)
2、錯誤背景:我想要自定義tomcat環境鏡像,通過build Dockerfile的方式
- Dockerfile 文件內容如下:
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、錯誤發生:執行到RUN yum -y install vim
就報錯,Cannot prepare internal mirrorlist: No URLs in mirrorlist
4、錯誤原因:
究其根因是版本問題
-
學習docker的影片,我跟著狂神的影片,為了減少錯誤,我選擇和他系統保持一致,安裝的軟體、鏡像、容器的版本等等(涉及到版本的)都保持一致
-
但是,問題在於,狂神的影片發布的時間和現在不同,影片的last版本,是他當時的last
大白話就是,狂神當時(last)最新的centos版本是7.xx,而現在(last)最新的版本的centos是8.xxx
出現版本原因的還有yum
-
伴隨著不同centos版本所兼容的yum,它的內容是不同的
-
舉例:Centos-vault-6.10.repo 和 Centos-vault-8.5.2111.repo的對比:發現版本6的內容比較少,它相對於8的話,沒有[centosplus]、[PowerTools]、[AppStream]
-
最最重要的是:本次問題報錯所沒有AppStream,而這個AppStream是版本8的centos才有的,是版本8的新增內容,在版本7是沒有它的,官網沒有提供!
-
☺ 認識到版本的重要性了吧,內容的增刪改!
二、正確解決方式
方式1:升級centos系統為版本8的,然後再使用build Dockerfile
方式2:涉及到centos版本的地方,指明版本
,如本文問題核心Dockerfile中的 FROM centos:7
- 指定dockerfile的centos版本
三、為什麼我知道”這個AppStream是版本8的centos才有的,是版本8的新增內容,在版本7是沒有它的,官網沒有提供”
1、線索1:搜索問題”Cannot prepare internal mirrorlist: No URLs in mirrorlist”
發現:
- 解釋了問題原因:
在2022年1月31日,CentOS團隊終於從官方鏡像中移除CentOS 8的所有包。
CentOS 8已於2021年12月31日壽終正非,但軟體包仍在官方鏡像上保留了一段時間。現在他們被轉移到//vault.centos.org
2、線索2:
跟著解決方案的文章,發現:
- 鏡像和倉庫:阿里、騰訊、中科院
//mirrors.ustc.edu.cn/help/centos.html
//mirrors.cloud.tencent.com/repo/
忽然發現,哦,原來7是真的沒有appstream
補充:看文章的時候,注意文章涉及到鏈接的地方,版本、版本、版本!
1)有時候文章提供了解決方法,但是版本和咱對不上,怎麼辦?
- 去掉一些參數,自己進入網站挑選合適自己的版本的
2)舉例:搜索No URLs in mirrorlist error,找到某一篇文章,他提供了一種解決方案:
3)提取鏈接到瀏覽器,把版本對應不上的參數去掉,得到:
3、線索3:搜索問題的時候,就算我輸入centos7,特意強調了centos 版本是7
發現:
- 搜索出來的版本都是8的,這個是一個提示點
☺ 為解決本文該問題—-我的折騰
結果是無效折騰
1、錯誤原因:
- 搜索得知錯誤原因,看到了centos版本是8,以為是所有的版本都一樣,然後,將別人文章centos版本8版本,直接改成7,以為就完美解決問題
在2022年1月31日,CentOS團隊終於從官方鏡像中移除CentOS 8的所有包。
CentOS 8已於2021年12月31日壽終正非,但軟體包仍在官方鏡像上保留了一段時間。現在他們被轉移到//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=//mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
#baseurl=//mirror.centos.org/$contentdir/$releasever/AppStream/$basearch/os/
baseurl=//vault.centos.org/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
② 執行命令:
yum clean all
yum makecache
2-2、又發生錯誤:
//vault.centos.org/centos/7/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Determining fastest mirrors
//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
//wiki.centos.org/yum-errors
If above article doesn't help to resolve this issue please use //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.
//vault.centos.org/centos/7/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
2-2、錯誤原因:
- 是因為yum已經更新了的原因導致的 //mirrors.163.com/centos/ 進官網可以看到已經更新到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=//mirrors.aliyun.com/centos/$releasever/appstream/$basearch/
gpgcheck=1
enabled=0
gpgkey=//mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
3、解決無效,嘗試其他解決方案:
(1)方式一:測試無效
(2)方式二:測試也無效
1)將源文件備份
cd /etc/yum.repos.d/ && mkdir backup && mv *repo backup/
2)下載阿里源文件
curl -o /etc/yum.repos.d/CentOS-Base.repo //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、又報錯
- 問題是:執行第四步
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.
//mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on //mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30000 milliseconds')
//mirrors.aliyun.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
//mirrors.aliyun.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
//mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on //mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
//mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on //mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
//mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on //mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30000 milliseconds')
//mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on //mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
//mirrors.aliyuncs.com/centos/7-stream/AppStream/x86_64/os/repodata/repomd.xml: [Errno 12] Timeout on //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系統本身所安裝的yum依賴包
rpm -qa|grep yum
2)卸載這些軟體包 rpm -e xx –nodeps
- 進入centos鏡像網站找到自己對應系統需要的yum包
- 查看系統的命令:
cat /etc/redhat-release
- 查看系統的位數:
file /bin/ls
- 下載yum依賴包:
- 網站://vault.centos.org/
- 找到對應版本的os/x86_64/Packages/
- 分別下載[注意:我的linux版本是centos7.6(1080)]:
wget //vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget //vault.centos.org/7.6.1810/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget //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
② 進入官網://mirrors.ustc.edu.cn/help/centos.html
- 自己先建立一個txt文件,內容拷貝進去後,修改名稱為CentOS-Base.repo
- 使用工具xftp,將CentOS-Base.repo 傳輸到/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=//mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=//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=//mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=//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=//mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=//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=//mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=//mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
③ 執行命令:
yum clean all
yum makecache
還報錯,你以為到這裡,我就放棄了嗎?
—yes, 我的貪吃蛇已經快排名第一了哈哈哈
- 繼續解決~~~
二、繼續我的不正確解決手段:
哇塞,玩完貪吃蛇的我,不一樣了,眼睛不一樣了,一瞅,立馬發現了,自己的centos的配置文件下的yum.repos.d/目錄下的文件和別人不同
- 發現缺少文件了
1、再搜索問題,發現缺少文件了
“將/etc/yum.repos.d/目錄下的CentOS-Base.repo、CentOS-AppStream.repo、CentOS-Extras.repo中的mirrorlist注釋掉,將baseurl 修改為阿里源……”
2、解決方式1【結果悲捶了,只剩下一個Centos-Base.repo文件了-----說明了備份的重要性
】:
將/etc/yum.repos.d 清空後,重新下載
# 刪除yum.repos.d目錄下所有文件
rm -f /etc/yum.repos.d/*
# 然後重新下載阿里的源(確保網路連接)--注意版本哦,我的centos是7的版本
wget -O /etc/yum.repos.d/CentOS-Base.repo //mirrors.aliyun.com/repo/Centos-7.repo
# 清理快取
yum clean all
☺ 心得:修改文件,記得備份!
● 所以,咱沒備份,配置文件全沒了,咱重置一下系統吧
☺ 重置Linux系統
- 在阿里雲官網上找到你購買的那個伺服器,點一下重置系統,選擇centos7,然後重置一下密碼
1、重置系統過後、發現/etc/yum.repos.d/目錄下:
- CentOS-Base.repo
- epel.repo
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
# 設置倉庫【默認是國外的,我們不要使用國外的,需要使用中國的阿里雲鏡像地址】
sudo yum-config-manager \
--add-repo \
//mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 更新yum 軟體包索引
yum makecache fast
# 3、安裝 Docker 引擎 docker-ce 社區 docker-ee 企業版
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)登錄阿里雲官網,點擊控制台,找到產品與服務,搜容器鏡像服務
- 鏡像加速器:
(2)配置使用:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["//o10wzpax.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
● 發現/etc/yum.repos.d/目錄下:
- CentOS-Base.repo
- docker-ce.repo
- epel.repo
- epel.repo.rpmnew
- epel-testing.repo
三、錯誤依舊
折騰累了,貪吃蛇也玩得手指起泡了,突然這次又火眼金睛,發現了阿里、騰訊鏡像中,好奇對比一下centos7—Base.repo 和 centos8—Base.repo,
還有,之前搜索發現:CentOS團隊終於從官方鏡像中移除CentOS 8的所有包。
CentOS 8已於2021年12月31日壽終正非,但軟體包仍在官方鏡像上保留了一段時間。現在他們被轉移到//vault.centos.org
順便對比一下:Centos-vault-6.10.repo 和 Centos-vault-8.5.2111.repo (因為沒有版本7的,所以找6的來對比)
恍惚之間,想到了時間是一把殺豬刀,現在是2022年了,而我的學習影片,狂神的Docker最新超詳細版教程通俗易懂影片,是2020年的
在下版本,有何貴幹!