alpine

1
2
3
4
5
6
7
8
9
10
11
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

centos7

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

Centos8(目前官方源下载错误, 先下载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
# debian9/10/11(一般情况下,将/etc/apt/sources.list文件中Debian默认的软件仓库地址和安全更新仓库地址修改为国内的镜像地址即可,比如将deb.debian.org和security.debian.org改为mirrors.<aliyun.com/tencent.com/163.com/huaweicloud.com/tuna.tsinghua.edu.cn/ustc.edu.cn>,并使用https访问,可使用如下命令,修改之后再运行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