'Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
I am trying to download java using yum on centOs which I specified in Dockerfile. After pulling centOs image the run crushed and throw this error!? also to mention that my server instance is AWS EC2!
Step 2/9 : RUN yum install java -y
---> Running in 39fc233aa965
CentOS Linux 8 - AppStream 184 B/s | 38 B 00:00
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
The command '/bin/sh -c yum install java -y' returned a non-zero code: 1
Solution 1:[1]
If you don't already have it, you'll need the gpg keys:
wget 'http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/centos-gpg-keys-8-3.el8.noarch.rpm'
sudo rpm -i 'centos-gpg-keys-8-3.el8.noarch.rpm'
Then it's as simple as transitioning like so:
dnf --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos
Don't worry -- it doesn't remove any repos, it simply temporarily ignores all of yours, and downloads information regarding the new mirrors.
You may at this point want to actually upgrade your packages:
sudo dnf distro-sync
You'll now be able to use "yum" as usual.
Solution 2:[2]
Try editing your dockerfile
FROM centos
RUN cd /etc/yum.repos.d/
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN yum -y install java
CMD /bin/bash
Refer to this code
Solution 3:[3]
I tried to use CentOS 8 with wsl and got the same error. Steps to fix the problem (as root):
# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
# dnf distro-sync
# dnf -y install java
The top voted answer did not work for me (by @Hashbrown). The answer with Dockerfile was not for my case either.
Solution 4:[4]
Go to /etc/yum.repos.d/
cd /etc/yum.repos.d/
Run
sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
sudo yum update -y
Then do what you want
Solution 5:[5]
Try this
FROM centos
RUN cd /etc/yum.repos.d/
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN yum -y install java
CMD /bin/bash
Solution 6:[6]
Please follow the below-mentioned steps:
Go to the /etc/yum.repos.d/ directory.
cd /etc/yum.repos.d/
Run the below commands to hash the mirror-list in all yum.repos.d files then replace the existed Baseurl with the vault.centos.org
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
Then run yum update or install any package you want
yum update -y
Solution 7:[7]
Go to /etc/yum.repos.d/
directory. Open .repo
file and manually edit mirrorlist from $releasever
to 8-stream
.
For example : /etc/yum.repos.d/CentOS-Linux-BaseOS.repo
open file in vi
sudo vi /etc/yum.repos.d/CentOS-Linux-BaseOS.repo
comment
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
#mirrorlist=http://......
within vi, copy paste
mirrorlist=http://......
lineyy and p
uncomment and edit the copied line by replacing $releasever to 8-stream
mirrorlist=http://mirrorlist.centos.org/?release=8-stream&arch=$basearch&repo=BaseOS&infra=$infra
save and exit vi
:wq
Repeat above 5-steps for other .repo files.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jeff Schaller |
Solution 2 | BigCat |
Solution 3 | |
Solution 4 | ddzzbbwwmm |
Solution 5 | Anup Kumar |
Solution 6 | Mahmudur Rahman |
Solution 7 |