35

I decided to use the multiple source form of COPY to save an intermediate command but when I run it the following error pops up:

Step 17/22 : COPY --chown=$APP_USER:$APP_USER Gemfile Gemfile.lock $APP_PATH When using COPY with more than one source file, the destination must be a directory and end with a / 

In the Dockerfile I have this:

ARG APP_PATH='/usr/share/app/' ONBUILD COPY --chown=$APP_USER:$APP_USER Gemfile Gemfile.lock $APP_PATH 

Edit

Just to be clear, this happens with ONBUILD present and without, it just so happened I pasted in the ONBUILD example


I've tried with and without the single quotes. The arg has a trailing slash and is a directory so why is the build not honouring it?

I'd like to make this Dockerfile into a template using ONBUILD so it'd be good if I can make sure the APP_PATH arg is populated with a default that will work.

5 Answers 5

68

In my case adding the (forward) slash at the end (following docker error message) was enough, like this:

COPY package*.json . # (fails!)

COPY package*.json ./ # (works:)

Sign up to request clarification or add additional context in comments.

1 Comment

While specifying any folder name, the folder name must end with a / symbol. For example: COPY p* ./app/ and not COPY p* ./app
15

The answer, as of Docker version 18.09.0, build 4d60db4, is don't do it this way because it won't work.

I ended up hard-coding the destination directory (and the chown args too):

ONBUILD COPY --chown=app:app Gemfile Gemfile.lock /usr/share/app/ 

Comments

1

Since COPY is in ONBUILD, ARG needs to be also in ONBUILD

You can think that Docker sort of copies (injects) your ONBUILD command right after the next FROM, at that stage it does not know your ARG if your ARG is not added with ONBUILD.

4 Comments

@iain did you try removing the quote?
Yes, it began without quotes.
Try removing --chown, currently it can't take ARGs.
After much fiddling around it's clear it can't work. Thanks for all your help, it's much appreciated and I gained some new insights into Docker that improved my build.
1

In my case, earlier I set buildKit to false, so Settings → Docker Engine

"features": { "buildkit": true } 

Comments

-1

I also encountered this, the issue is that Docker expects the destination to be a directory when copying multiple files.

I resolved it by changing the destination to a directory that ends with /. This will copy all files that start with package and end with .json into the /app directory.

Instead of this:

COPY package* .json . 

Do this:

COPY package*.json ./ 

This worked perfectly for me.

1 Comment

This exact thing was already posted three years ago

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.