在Dockerfile中如何添加一个没有提交的文件? [英] in the Dockerfile how to ADD a file without a commit?

查看:374
本文介绍了在Dockerfile中如何添加一个没有提交的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个〜300Mb压缩的本地文件,我添加到码头图像。下一个状态然后提取图像。



问题是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

问题:是否有一个解决方案来添加本地文件而不会导致提交?



一个选项是运行一个简单的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

另一个选项是提取压缩文件在容器启动而不是构建时间,但我宁愿保持启动尽可能快。

解决方案

根据文档,如果您从本地文件系统传递存档文件(不是URL)到Docker文件中的ADD(目标路径,而不是路径+文件名),它将解压缩文件到目录中。


如果< src>是以公认的压缩格式
(identity,gzip,bzip2或xz)的本地tar存档,则将其解包为目录。
来自远程URL的资源未被解压缩。当目录是
复制或解包时,它与tar -x具有相同的行为:结果是
的联合:



1)无论目的地路径中存在什么,以及2)
源代码树的内容,冲突解决为有利于2.


尝试:

  ADD /files/apache-stratos.zip / opt / 

看看文件是否存在,无需进一步解压缩。


I have a ~300Mb zipped local file that I add to a docker image. The next state then extracts the image.

The problem is that the ADD statement results in a commit that results in a new file system layer makes the image ~300Mb larger than it needs to be.

ADD /files/apache-stratos.zip /opt/apache-stratos.zip
RUN unzip -q apache-stratos.zip && \
    rm apache-stratos.zip && \
    mv apache-stratos-* apache-stratos

Question: Is there a work-around to ADD local files without causing a commit?

One option is to run a simple web server (e.g. python -m SimpleHTTPServer) before starting the docker build, and then using wget to retrieve the file, but that seems a bit messy:

RUN wget http://localhost:8000/apache-stratos.zip && \
    unzip -q apache-stratos.zip && \
    rm apache-stratos.zip && \
    mv apache-stratos-* apache-stratos

Another option is to extract the zipped file at container start up instead of build time, but I would prefer to keep the start up as quick as possible.

解决方案

According to the documentation, if you pass an archive file from the local filesystem (not a URL) to ADD in the Dockerfile (with a destination path, not a path + filename), it will uncompress the file into the directory given.

If <src> is a local tar archive in a recognized compression format (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.

try:

ADD /files/apache-stratos.zip /opt/

and see if the files are there, without further decompression.

这篇关于在Dockerfile中如何添加一个没有提交的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆