3

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.

Tomáš Záluský
  • 10,735
  • 2
  • 36
  • 64

1 Answers1

4

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

Tomáš Záluský
  • 10,735
  • 2
  • 36
  • 64
  • The more idiomatic way would be `COPY csv /` – super Dec 09 '21 at 20:30
  • Interesting but empty directory fails on next Docker instruction `ADD anothernonemptydir/** /anothernonemptydir/` with `failed to export image: failed to create image: failed to get layer sha256:37e90a5f...: layer does not exist` error; for nonempty directory it fails on later `chmod` (probably was not created either). – Tomáš Záluský Dec 09 '21 at 22:31