skip to Main Content

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

10

Answers


  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.

    Login or Signup to reply.
  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

    failed-metadata-repo-appstream-centos-8

    Login or Signup to reply.
  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.

    Login or Signup to reply.
  4. 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
    
    Login or Signup to reply.
  5. 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.

    Login or Signup to reply.
  6. 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

    Login or Signup to reply.
  7. 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

    Login or Signup to reply.
  8. 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-*
    
    Login or Signup to reply.
  9. 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.

    Login or Signup to reply.
  10. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search