change repository in centos 8

CentOS-Base.repo

modify /etc/yum.repos.d/CentOS-Base.repo

1
2
3
4
5
6
7
8
[BaseOS]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

CentOS-AppStream.repo

modify /etc/yum.repos.d/CentOS-AppStream.repo

1
2
3
4
5
6
7
8
[AppStream]
name=CentOS-$releasever - AppStream
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/AppStream/$basearch/os/
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

other

other file not avaliable in default, can change to ali repository as well.
https://mirrors.aliyun.com/centos/8/extras/x86_64/os/

reload matadata
yum makecache

when modifying the source on a docker image, use the following description in the Dockerfile to build

1
2
3
4
5
6
7
RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
COPY CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo

RUN mv /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-AppStream.repo_bak
COPY CentOS-AppStream.repo /etc/yum.repos.d/CentOS-AppStream.repo

RUN yum makecache

http://www.voycn.com/article/centos8-peizhialiyuan-zuixiaohuaanzhuang