Alpine

1
2
3
4
5
6
7
8
9
10
set -eux \
&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
&& apk update

# 切换时区
set -eux \
&& apk add --no-cache tzdata \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata

Ubuntu

镜像中文乱码现象处理:

1
2
3
4
# 在 Dockerfile 中添加
ENV LANG C.UTF-8
# ENV LANGUAGE C.UTF-8 # 可不配置
# ENV LC_ALL C.UTF-8 # 可不配置

阿里云镜像配置:

1
2
3
4
5
6
7
8
# 替换 <xxx> 为 aliyun.com / tencent.com / 163.com / huaweicloud.com / tuna.tsinghua.edu.cn / ustc.edu.cn
# 如果是国内 Ubuntu,改 archive 为 cn.archive
sed -i "s@http://\(archive\|security\).ubuntu.com@https://mirrors.<xxx>@g" /etc/apt/sources.list \
&& apt-get clean \
&& apt-get update -y

# 更换时区
ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

CentOS 7

1
2
3
4
5
6
7
8
yum -y install wget \
&& mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak \
&& wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
&& yum clean all \
&& yum makecache

# 更换时区
ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

注意mirrorlist.centos.org 这个源已停用,所以当执行 yum 指令安装软件时可能会报错,还需要修改另外一个 repo 文件 CentOS-SCLo-scl.repo,然后执行 yum clean all && yum makecache

修改 CentOS-SCLo-scl.repo 文件:

1
2
3
4
5
6
7
8
# 将 [centos-sclo-rh] 下的内容改为下面内容

[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=http://vault.centos.org/centos/7/sclo/$basearch/rh/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

CentOS 8

注意:目前官方源下载错误,先下载 wget 行不通,最好是将镜像源文件先下载下来,再 copy 到指定地方。

1
2
3
4
5
cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak \
&& wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-8-reg.repo \
&& mv CentOS-Linux-AppStream.repo CentOS-Linux-AppStream.repo.bak \
&& mv CentOS-Linux-BaseOS.repo CentOS-Linux-BaseOS.repo.bak \
&& yum clean all && yum makecache

Debian

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Debian 9/10/11
# 一般情况下,将 /etc/apt/sources.list 文件中 Debian 默认的软件仓库地址和安全更新仓库地址修改为国内的镜像地址即可
# 比如将 deb.debian.org 和 security.debian.org 改为 mirrors.<xxx>,并使用 HTTPS 访问
# 替换 <xxx> 为 aliyun.com / tencent.com / 163.com / huaweicloud.com / tuna.tsinghua.edu.cn / ustc.edu.cn
# 修改之后再运行 apt update 更新索引

sed -i "s@http://\(deb\|security\).debian.org@https://mirrors.<xxx>@g" /etc/apt/sources.list \
&& apt update -y \
&& apt upgrade -y

# Debian Buster 以上版本默认支持 HTTPS 源
# 如果遇到无法拉取 HTTPS 源的情况,请先使用 HTTP 源并安装:
sudo apt install apt-transport-https ca-certificates

# 更换时区
ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime