yum in a centos:7 image cannot fetch the mirror list
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=containerShort answer
The centos image is end of life: Docker Hub says all its tags are EOL. yum in a centos:7 image still asks mirrorlist.centos.org for mirrors and cannot get them. For a frozen legacy build, replace the repo files with one that points at vault.centos.org/7.9.2009. For a maintained system, change the base image.
Fix it fast
1Find out which cause you have
Open the repo files in the image and see whether they use mirrorlist lines. Then check which architecture the build runs on, because the vault path below is for x86_64.
docker run --rm centos:7 sh -c 'ls /etc/yum.repos.d; uname -m'2Match what you see, then jump to its fix
What does the error look like?
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=containeryum install fails in a centos:7 image during docker build
Cause 1 of 2
The repo files still point at the retired mirror list
1Check
Docker Hub marks all tags of the centos image as EOL (CentOS Linux end of life), and the content is archived at vault.centos.org. The vault has a 7.9.2009 tree with os, updates and extras folders; each of those lists an x86_64 directory.
docker run --rm centos:7 sh -c 'cat /etc/yum.repos.d/*.repo | grep -i mirrorlist'2Fix
Remove the old repo files and add one with fixed baseurl lines for the 7.9.2009 vault trees. Do this before the first yum command. The vault gets no updates, so treat the image as frozen.
FROM centos:7
RUN rm -f /etc/yum.repos.d/*.repo && printf '[base]\nname=CentOS 7 vault os\nbaseurl=https://vault.centos.org/7.9.2009/os/$basearch/\nenabled=1\n[updates]\nname=CentOS 7 vault updates\nbaseurl=https://vault.centos.org/7.9.2009/updates/$basearch/\nenabled=1\n[extras]\nname=CentOS 7 vault extras\nbaseurl=https://vault.centos.org/7.9.2009/extras/$basearch/\nenabled=1\n' > /etc/yum.repos.d/vault.repo
RUN yum -y install curl3Verify
Build again and run a yum command.
docker build -t legacy-app . && docker run --rm legacy-app yum repolistConfirmed by vault.centos.org
Cause 2 of 2
The base image has no supported tags, so any fix is temporary
1Check
The centos page on Docker Hub lists no supported tags and tells users to adjust their usage. Vault repos receive no updates, so security fixes never arrive.
docker run --rm centos:7 cat /etc/os-release2Fix
For anything that is not a frozen legacy build, change the base to a maintained RHEL-compatible image such as Rocky Linux (Docker Hub lists the tags 8, 9 and 10) and rebuild. Package names and versions can differ, so rerun the build and its tests.
FROM rockylinux:9
RUN dnf -y install curl3Verify
The build runs without any vault workaround.
docker build -t my-app . && docker run --rm my-app curl --versionConfirmed by hub.docker.com
How do I stop it coming back?
- Do not use centos:latest or centos:7 in new Dockerfiles; pick a maintained base and pin its tag.
- Label images that depend on the vault as frozen and keep them off the public internet.
- Keep the vault repo block in one Dockerfile layer at the top so it is easy to delete when the base is replaced.
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
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fix