https://help.aliyun.com/zh/ecs/user-guide/manage-and-use-linux-software-repositories#25e338c63cttl

centos

centos7切阿里云源

ubuntu

https://mirrors.ustc.edu.cn/help/index.html

https://www.cnblogs.com/chentiao/p/17352748.html

在Dockerfile中将apt-get源更换为中国国内源,您可以通过以下步骤完成:

在Dockerfile的开头添加以下内容:

# 设置为中国国内源 阿里云
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
RUN sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list

# 如果不行可以试试中科大
RUN sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

这将使用 sed 命令替换默认的 Ubuntu 源为阿里云镜像。

Debian

如果您使用的是 Debian 发行版,则可以使用以下命令替换默认源为中科大的镜像:

https://developer.aliyun.com/mirror/debian/?spm=a2c6h.25603864.0.0.1e7129e8wOBTrV


# 优化apt源和安装依赖
# 中科大
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

# 阿里云
#RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
#RUN sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list

保存并构建Docker镜像,您的Dockerfile中的 apt-get 命令将使用中国国内源。

alpin


# 配置阿里云镜像源
RUN echo "<http://mirrors.aliyun.com/alpine/v3.12/main>" > /etc/apk/repositories && \\
    echo "<http://mirrors.aliyun.com/alpine/v3.12/community>" >> /etc/apk/repositories

请注意,使用国内源可能会对软件包的可用性和稳定性产生一些影响。建议在更改源之前先测试您的Docker镜像,以确保所有依赖项都可用。