Dockerfile中的条件COPY / ADD? [英] Conditional COPY/ADD in Dockerfile?
问题描述
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屋!