【问题标题】:Copy directory into docker build no matter if empty or not - fails on "COPY failed: no source files were specified"无论是否为空,都将目录复制到 docker build - 在“复制失败:未指定源文件”时失败
【发布时间】:2022-01-14 14:57:59
【问题描述】:

我在docker build 的上下文目录中有目录csv。我想在所有情况下都将它复制到 docker 映像中(对于主机中的空目录,会创建映像内的空目录,对于主机中的非空目录,它会与所有内容一起复制)。

COPY csv/* /csv/ 在目录为空时给出COPY failed: no source files were specified 错误。

我在 SO 上发现的类似问题在设置或意图(multistage buildcopying existing jarcertainly existing file)上与我的情况不同,所以我在这里选择问答式,而不是用不相关的答案来混淆问题。 This Github issue 也有关系。

【问题讨论】:

    标签: docker dockerfile docker-build docker-copy


    【解决方案1】:

    解决办法是用

    COPY csv/. /csv/
    

    This question 给了我一个提示(尽管我想要的行为对于它的 OP 来说是不需要的)。

    【讨论】:

    • 更惯用的方式是COPY csv /
    • 有趣但空目录在下一条 Docker 指令 ADD anothernonemptydir/** /anothernonemptydir/ 上失败,并出现 failed to export image: failed to create image: failed to get layer sha256:37e90a5f...: layer does not exist 错误;对于非空目录,它稍后会失败chmod(可能也没有创建)。
    猜你喜欢
    • 2020-05-02
    • 1970-01-01
    • 2019-10-27
    • 1970-01-01
    • 2021-05-17
    • 2020-05-18
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多