我有一个~300Mb压缩的本地文件,我添加到docker镜像.然后下一个状态提取图像.
问题是ADD语句导致提交导致新的文件系统层使图像大〜300Mb比它需要的大.
ADD /files/apache-stratos.zip /opt/apache-stratos.zip
RUN unzip -q apache-stratos.zip && \
rm apache-stratos.zip && \
mv apache-stratos-* apache-stratos
一种选择是在启动docker构建之前运行一个简单的Web服务器(例如python -m SimpleHTTPServer),然后使用wget来检索文件,但这看起来有点乱:
RUN wget http://localhost:8000/apache-stratos.zip && \
unzip -q apache-stratos.zip && \
rm apache-stratos.zip && \
mv apache-stratos-* apache-stratos
最佳答案
根据the documentation,如果您将存档文件从本地文件系统(不是URL)传递到Dockerfile中的ADD(具有目标路径,而不是路径文件名),它会将文件解压缩到给定的目录中.
If
(identity,gzip,bzip2 or xz) then it is unpacked as a directory.
Resources from remote URLs are not decompressed. When a directory is
copied or unpacked,it has the same behavior as tar -x: the result is
the union of:1) Whatever existed at the destination path and 2) The contents of the
source tree,with conflicts resolved in favor of “2.” on a file-by-file basis.
尝试:
ADD /files/apache-stratos.zip /opt/
并查看文件是否存在,无需进一步解压缩.