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

3.5k Views Asked by At

I have directory csv in context directory of docker build. I want to copy it into docker image in all circumstances (for empty directory in host an empty directory inside image is created, for nonempty directory in host it is copied with all content).

The COPY csv/* /csv/ gives COPY failed: no source files were specified error when the directory is empty.

Similar questions I found on SO are differing from my case in either setup or intention (multistage build, copying existing jar, certainly existing file) so I choose Q&A-style here rather than messing question with unrelated answer. This Github issue is also related.

1

There are 1 best solutions below

2
On BEST ANSWER

The solution is to use

COPY csv/. /csv/

This question gave me a hint (although the behavior desired by me is unwanted for its OP).