moby: "COPY foo/* bar/" not work if no file in foo/

Example:

Step 0 : COPY source/* /source/
INFO[0001] No source files were specified

If there isn’t any file in source/ directory, the build will fail.

Expected behavior: Continue if no file matches source/*.

This is very annoyed when COPY is provided as ON BUILD instruction.

Docker information: https://github.com/icy/docker/blob/master/bugs/volume_bug/docker.info.txt

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 27
  • Comments: 30 (12 by maintainers)

Commits related to this issue

Most upvoted comments

A Try/Catch block would solve this and will be useful for other purposes too:

TRY
COPY foo/* /bar/
CATCH
COPY baz/* /bar/

What do people think about reopening https://github.com/docker/docker/pull/13813 (adding a --ignore-error type of flag) since the builder restrictions are now gone?

ping @docker/maintainers

If you are reporting a new issue, PLEASE make sure that does not have any duplicates already open.

How? scanning all > 800 tickets? Where is QA/ tester team of Docker?

COPY source/. /source/ works for me (i.e. copies directory when empty or not). Details here.

I believe this was intentional. Try:

$ cp foo* /tmp/
cp: cannot stat ‘foo*’: No such file or directory
$ echo $?
1

Doing what we see on the cmd line makes sense.

That being said, I can understand that this might cause some issues for people since, unlike in a script, you don’t have the option of telling Docker’s build process to continue.

I think the options are: 1 - do nothing, leave it as is 2 - don’t make this a build-stopping error (perhaps keep the info msg for debugging purposes) 3 - add a --ignore-missing type of option to COPY/ADD so the user can explicitly tell us they’re ok with missing source files. E.g. COPY --ignore-missing source/* source/

I’m ok with either 2 or 3, with a slight preference for 3 because doing 2 would be changing the current semantics and might break people.

ping @tiborvass @erikh @tianon

I’m keeping this issue open, but this will be resolve if the other proposal is implemented 👍

Discussing this in the maintainers session, and we think having the COPY --mount option would solve this use case (and many others); https://github.com/moby/moby/issues/32507. Contributions for that are welcome (but @tonistiigi mentions that once we switch to the new BuildKit, implementing would be quite easy 😇 )