Maaz Zindani

Loading the index…

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

yum in a centos:7 image cannot fetch the mirror list

ErrorCould not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container

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

  • Applies to Docker Engine 28, centos:7 image, yum
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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'
  2. 2Match what you see, then jump to its fix

    1. 1The error names mirrorlist.centos.org and release=7The repo files still point at the retired mirror listFix
    2. 2The image is centos:7 or centos:latest and the build is for something that will keep runningThe base image has no supported tags, so any fix is temporaryFix

What does the error look like?

  • Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container
  • yum 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 curl

3Verify

Build again and run a yum command.

docker build -t legacy-app . && docker run --rm legacy-app yum repolist

Confirmed by vault.centos.org

Did this fix it?

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-release

2Fix

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 curl

3Verify

The build runs without any vault workaround.

docker build -t my-app . && docker run --rm my-app curl --version

Confirmed by hub.docker.com

Did this fix it?

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

Next step

Want this handled for good?

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