Dockerfile中的条件COPY / ADD? [英] Conditional COPY/ADD in Dockerfile?

查看:836
本文介绍了Dockerfile中的条件COPY / ADD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Dockerfiles里面,我想把一个文件复制到我的图片中,如果它存在,那么pip的require.txt文件似乎是一个很好的候选人,但是如何实现?

  COPY(require.txt if test -e requirements.txt; fi)/ destination 
...
如果test -e requirements.txt运行;然后点安装-r requirements.txt; fi

 code>如果test -e requirements.txt;然后
COPY requiements.txt / destination;
fi
运行如果test -e requirements.txt;然后点安装-r requirements.txt; fi

感谢:)

解决方案

目前不支持(因为我怀疑它会导致不可重现的图像,因为相同的Docker文件会根据文件的存在而复制或不复制)。



仍然要求,在问题13045 中,使用通配符: COPY foo / * bar /不工作,如果没有文件在foo (2015年5月)。

它不会实现现在(2015年7月)在Docker,但另一个构建工具,如 bocker 可以支持这个。


Inside of my Dockerfiles I would like to COPY a file into my image if it exists, the requirements.txt file for pip seems like a good candidate but how would this be achieved?

COPY (requirements.txt if test -e requirements.txt; fi) /destination
...
RUN  if test -e requirements.txt; then pip install -r requirements.txt; fi

or

if test -e requirements.txt; then
    COPY requiements.txt /destination;
fi
RUN  if test -e requirements.txt; then pip install -r requirements.txt; fi

Thanks :)

解决方案

This isn't currently supported (as I suspect it would lead to non-reproducible image, since the same Dockerfile would copy or not the file, depending on its existence).

This is still requested, in issue 13045, using wildcards: "COPY foo/* bar/" not work if no file in foo" (May 2015).
It won't be implemented for now (July 2015) in Docker, but another build tool like bocker could support this.

这篇关于Dockerfile中的条件COPY / ADD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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