dnf fails to download repo metadata in a CentOS 8 Docker build
dnf fails while downloading metadata for the BaseOS or AppStream repository in RUN dnf installShort 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.
Fix it fast
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'2Match what you see, then jump to its fix
What does the error look like?
dnf fails while downloading metadata for the BaseOS or AppStream repository in RUN dnf installThe 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.repo3Verify
Metadata downloads and a package installs.
docker build --no-cache -t my-app .Confirmed by dnf.readthedocs.io
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" Dockerfile2Fix
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:93Verify
The build runs without the vault workaround and dnf can install packages.
docker build --no-cache -t my-app .Confirmed by hub.docker.com
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
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
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 fixServers
Docker build fails with apk: not found in a Python or Ubuntu image
/bin/sh: 1: apk: not found
apk is the package manager of Alpine Linux only.
2 causes, each with a fix