Ubuntu/Debian版:
在Dockerfile中添加如下两句代码:
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get clean
更新apt源的Dockerfile如下:
FROM ubuntu:latest
MAINTAINER CFSoft CO.,Ltd. "wdmsyf@sina.com"
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get clean
RUN apt-get update
CentOS 7:
1宿主机
宿主机内运行:
#获取国内源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#到/etc/yum.repos.d/目录下查找源
cd /etc/yum.repos.d/
#将源拷贝到你Dockerfile所在目录
2.Dockerfile编写
#使用 ADD 命令将 CentOS-Base.repo 拷贝到目标基础镜像的目录下
ADD CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo
#更新yum源|如果你不需要更新版本,可以不执行此命令(升级后的版本太高可能导致原有软件不能运行)
#RUN yum -y update
#运行yum makecache生成缓存,便于查找
RUN yum makecache
#如果觉得占用磁盘空间,可以使用以下指令清除缓存
RUN yum clean