Dockerfile中的条件复制/添加? [英] Conditional COPY/ADD in Dockerfile?

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

问题描述

在我的 Dockerfiles 中,如果存在,我想将一个文件复制到我的映像中,pip 的 requirements.txt 文件似乎是一个不错的候选者,但是如何实现呢?

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

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

推荐答案

目前不支持(因为我怀疑它会导致无法重现的图像,因为相同的 Dockerfile 会复制或不复制文件,这取决于它的存在).

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).

这仍然是请求,在 issue 13045 中,使用通配符:"COPY foo/* bar/"如果 foo 中没有文件则不起作用"(2015 年 5 月).
它现在(2015 年 7 月)不会在 Docker 中实现,而是另一个构建工具,例如 bocker 可以支持这一点.

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中的条件复制/添加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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