Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

dnf fails to download repo metadata in a CentOS 8 Docker build

Errordnf fails while downloading metadata for the BaseOS or AppStream repository in RUN dnf install

Short answer

CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors. A centos:8 image still has repo files that ask the mirror list for URLs and gets none. Replace the repo files with ones pointing at vault.centos.org, or build on a distribution that is still maintained.

  • Applies to CentOS Linux 8 images, dnf 4, Docker Engine 28
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print which repo files the image has and whether they use a mirror list. The OS release line tells you which CentOS Linux version the image carries.

    docker run --rm centos:8 cat /etc/os-release
    docker run --rm centos:8 sh -c 'grep -H mirrorlist /etc/yum.repos.d/*.repo'
  2. 2Match what you see, then jump to its fix

    1. 1The failing repos are BaseOS and AppStream, and the repo files contain mirrorlist= linesThe repo files ask a mirror list that no longer has URLs for CentOS 8Fix
    2. 2FROM centos:8, FROM centos or centos:latest in the DockerfileThe base image is end of life and has no maintained tagsFix

What does the error look like?

  • dnf fails while downloading metadata for the BaseOS or AppStream repository in RUN dnf install
  • The same Dockerfile built fine before 2022

Cause 1 of 2

The repo files ask a mirror list that no longer has URLs for CentOS 8

1Check

CentOS Linux 8 content was removed from the mirrors and archived at vault.centos.org. A repo section needs exactly one of baseurl, mirrorlist or metalink; the image's files use the mirror list. The vault holds the last tree, 8.5.2111, with BaseOS and AppStream metadata.

docker run --rm centos:8 sh -c 'grep -H -E "mirrorlist|baseurl" /etc/yum.repos.d/*.repo'

2Fix

Remove the old repo files and add one that uses baseurl lines for the 8.5.2111 trees in the vault. In a Dockerfile, do it before the first dnf command. The vault gets no updates, so treat the image as frozen.

RUN rm -f /etc/yum.repos.d/*.repo
RUN printf '[baseos]\nname=CentOS 8 BaseOS vault\nbaseurl=https://vault.centos.org/8.5.2111/BaseOS/$basearch/os/\nenabled=1\n[appstream]\nname=CentOS 8 AppStream vault\nbaseurl=https://vault.centos.org/8.5.2111/AppStream/$basearch/os/\nenabled=1\n' > /etc/yum.repos.d/vault.repo

3Verify

Metadata downloads and a package installs.

docker build --no-cache -t my-app .

Confirmed by dnf.readthedocs.io

Did this fix it?

Cause 2 of 2

The base image is end of life and has no maintained tags

1Check

Docker Hub states that all tags of the centos image are EOL, and the CentOS project says CentOS Linux 8 users were not moved to a successor automatically; CentOS Stream is the successor line. The vault is archive only: it does not get security updates.

grep -n "^FROM" Dockerfile

2Fix

For anything that stays in use, rebuild on a maintained distribution. Rocky Linux publishes images on Docker Hub (current ones under rockylinux/rockylinux).

docker pull rockylinux:9
# Dockerfile
FROM rockylinux:9

3Verify

The build runs without the vault workaround and dnf can install packages.

docker build --no-cache -t my-app .

Confirmed by hub.docker.com

Did this fix it?

How do I stop it coming back?

  • Do not build new images on centos:latest or other EOL tags; pick a base image that still gets security updates.
  • Use the vault only for pinned legacy builds, and mark those images as frozen.
  • Pin base image versions in FROM so a retired tag fails loudly in a review, not in production.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

A dev container port does not open in the browser when Docker runs on a remote host

If your application only accepts calls from localhost, it will reject connections from published ports

Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.