将目录复制到 docker 构建中,无论是否为空 - 在 "COPY failed: no source files were specified" 上失败

Copy directory into docker build no matter if empty or not - fails on "COPY failed: no source files were specified"

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

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

我在 SO 上发现的类似问题在设置或意图上与我的情况不同(, copying existing jar, certainly existing file) so I choose Q&A-style here rather than messing question with unrelated answer. This Github issue 也相关。

解决方法是使用

COPY csv/. /csv/

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