85

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
Yusuf
  • 2,295
  • 7
  • 15
  • 34
  • Does this answer your question? [Centos through VM - no URLs in mirrorlist](https://stackoverflow.com/questions/70926799/centos-through-vm-no-urls-in-mirrorlist). The [top-voted answer](https://stackoverflow.com/a/70964301/3025856) below suggests that this (now closed) question includes an answer to this question. – Jeremy Caney Feb 09 '22 at 21:16

11 Answers11

148

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

failed-metadata-repo-appstream-centos-8

BigCat
  • 1,601
  • 1
  • 3
  • 4
72

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.

Jeff Schaller
  • 2,352
  • 5
  • 23
  • 38
Hashbrown
  • 12,091
  • 8
  • 72
  • 95
  • One first has to remove all packages from the `PowerTools` repository before `distro-sync`, which are being duplicated. Some of `mirror.centos.org` seems to be `vault.centos.org` (archived) now. – Martin Zeitler Feb 12 '22 at 12:59
  • Unfortunately, I hit this error when trying to download wget to the base centos-8 image. @BigCat's suggestion worked for me. – Kevin Mooney May 12 '23 at 13:52
62

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

wsdzbm
  • 3,096
  • 3
  • 25
  • 28
16

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.

  • I think "dnf distro-sync" will undo the changes made by the 2 prior sed commands – user1754036 Apr 07 '22 at 21:25
  • dnf does not change its configuration under /etc . Checkout **man dnf**. It just upgrades, downgrades or keeps selected installed packages to match the latest version available from any enabled repository. – Daniel Andrzejewski May 09 '22 at 16:16
  • 1
    And yet, after the "dnf distro-sync" finishes running, entering grep "baseurl=http://mirror.centos.org" /etc/yum.repos.d/CentOS-* shows what it would show before the 2nd sed command. https://pastebin.com/PBbwES3A If we skip the "dnf distro-sync" command, java will install. – user1754036 Jun 06 '22 at 14:12
  • Here's the full output generated by dnf distro-sync https://pastebin.com/mMZkkbCL note the changes to /etc starting at line 1476 – user1754036 Jun 06 '22 at 14:18
14

Use these commands to update centOS8.0 on AWS EC2:

sudo sed -i -e "s|mirrorlist=|#mirrorlist=|g" \
    -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" \
        /etc/yum.repos.d/CentOS-*
tripleee
  • 175,061
  • 34
  • 275
  • 318
sfl0r3nz05
  • 547
  • 8
  • 14
14

CentOS 8 reached EOL on 2021-12-31 (announcement).

Therefore, the URLs to the mirrors don't work anymore. Instead of using sed to modify the URLs to point to the archived mirrors, CentOS officially recommends to convert from CentOS Linux 8 to CentOS Stream 8 via:

dnf --disablerepo '*' --enablerepo extras swap centos-linux-repos centos-stream-repos
dnf distro-sync

After that, dnf/yum will work again.

Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49
stackprotector
  • 10,498
  • 4
  • 35
  • 64
3

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
Anup Kumar
  • 61
  • 3
0

Please follow the below-mentioned steps:

  1. Go to the /etc/yum.repos.d/ directory.

    cd /etc/yum.repos.d/

  2. 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-*

  3. Then run yum update or install any package you want

    yum update -y

Mahmud
  • 119
  • 1
  • 7
0

Update your docker file with below. It should work.

    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 update -y
viratpuar
  • 524
  • 1
  • 5
  • 22
0

Mine had to be a mixture of some of the other answers. I used latest (as of a couple days ago) CentOS with Docker default image. (sudo failed as I was already in 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-*
yum install PACKAGE

no update of yum was needed

ProsperousHeart
  • 188
  • 1
  • 14
-1

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

  1. open file in vi

    sudo vi /etc/yum.repos.d/CentOS-Linux-BaseOS.repo

  2. comment mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra

    #mirrorlist=http://......

  3. within vi, copy paste mirrorlist=http://...... line

    yy and p

  4. 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

  5. save and exit vi

    :wq

Repeat above 5-steps for other .repo files.

Sathish
  • 12,453
  • 3
  • 41
  • 59