在 Dockerfile 中,您可以使用以下步骤来更新 CentOS 8 的阿里源镜像:
- 在 Dockerfile 的开头使用
FROM
命令来指定 CentOS 8 的基础镜像,如下所示:
FROM centos:8
- 使用
RUN
命令来执行一条 shell 命令,以更新阿里源镜像,如下所示:
RUN sed -i's/mirrorlist=https/mirrorlist=http/g' /etc/yum.repos.d/CentOS-Base.repo && \
sed -i 's/$releasever/8/g' /etc/yum.repos.d/CentOS-Base.repo && \
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
- 使用
RUN
命令来执行一条 shell 命令,以清除缓存,如下所示:
RUN yum clean all
在执行完上述步骤后,CentOS 8 的阿里源镜像就已经更新完毕。
注意:请确保在每个 RUN
命令后面都有一个反斜杠 () 来换行,这样才能够正确地将多条命令组合成一个单一的 shell 命令。