You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Without BuildKit, both cases produce an error (note that an error is only produced if the wildcard matches multiple files):
Sending build context to Docker daemon 2.607kBStep 1/2 : FROM busybox ---> f0b02e9d092dStep 2/2 : COPY one two /destWhen using COPY with more than one source file, the destination must be a directory and end with a /
I would expect both builders to produce the same result. This error was added in moby/moby#8076 (original implementation to support multiple source in COPY/ADD). Although that PR does not mention why the error was added, I expect this was done to prevent ambiguity, and to account for the follow-up PR to implement wildcard copy.
Bug: copying multiple sources does not create directory, and overwrites destination
mkdir foo &&cd foo
echo"I am one"> one
DOCKER_BUILDKIT=1 docker build --no-cache --progress=plain -f- .<<'EOF'FROM busyboxCOPY * /destRUN ls -la /destRUN cat /destEOF#7 [3/4] RUN ls -la /dest#7 sha256:b50a5cfb31616d8591990732aba8ccf693668d610b2a4e0d371306c11d640d47#7 0.257 -rw-r--r-- 1 root root 9 Nov 26 10:52 /dest#7 DONE 0.3s#8 [4/4] RUN cat /dest#8 sha256:96703a4cf33b9584ca11a545c8a1e6dd2b4d7b0d3ea5dc94a109366d4cc20e2e#8 0.256 I am one#8 DONE 0.3s
Now create a second file in the current directory, and repeat the build;
echo"I am two"> two
DOCKER_BUILDKIT=1 docker build --no-cache --progress=plain -f- .<<'EOF'FROM busyboxCOPY * /destRUN ls -la /destRUN cat /destEOF#7 [3/4] RUN ls -la /dest#7 sha256:e33a1a1c73bb96096bb5101a3d4391ee9894cc9a84faa7cfa8f016d8f9df7394#7 0.280 -rw-r--r-- 1 root root 9 Nov 26 10:53 /dest#7 DONE 0.4s#8 [4/4] RUN cat /dest#8 sha256:4f1c74800842289bd292c2c237042f2bd7d30bbd1e23728e407accc1897fac95#8 0.287 I am two#8 DONE 0.4s
As can be seen in the above, BuildKit creates a file named dest, copies one to that file, and then overwrites the file with file two
Note that adding a trailing / to the destination fixes this situation;
DOCKER_BUILDKIT=1 docker build --no-cache --progress=plain -f- .<<'EOF'FROM busyboxCOPY * /dest/RUN ls -la /destRUN cat /destEOF#7 [3/4] RUN ls -la /dest#7 sha256:023e34d9abccf53df55a31b2a935227b5b9d847931466a98d65f975b9aa944a4#7 0.265 total 16#7 0.265 drwxr-xr-x 2 root root 4096 Nov 26 11:11 .#7 0.265 drwxr-xr-x 1 root root 4096 Nov 26 11:11 ..#7 0.265 -rw-r--r-- 1 root root 9 Nov 26 10:59 one#7 0.265 -rw-r--r-- 1 root root 9 Nov 26 10:59 two#7 DONE 0.4s#8 [4/4] RUN cat /dest#8 sha256:fde1c24f2aca4ddf7192ad912ec51afdae2879dafb6100b2d23b59b60aadef73#8 0.262 cat: read error: Is a directory#8 ERROR: executor failed running [/bin/sh -c cat /dest]: exit code: 1
------
> [4/4] RUN cat /dest:
------
executor failed running [/bin/sh -c cat /dest]: exit code: 1
What I expected
I expected BuildKit to;
produce an error that dest should have a trailing / if multiple sources are specified
produce an error that dest should have a trailing / if SRC uses a wildcard / globbing, and matches multiple files
create a directory named dest, and to copy files one and two into that directory
While 1. and 2.could be "optional", I think we should produce an error because;
without trailing slash, the instruction can be ambiguous (in the case of explicitly specifying multiple sources).
forcing a trailing / also (see earlier example) prevents the problem of creating a file (and overwriting), which makes the error useful to have
This is a combination of two issues;
COPY
(andADD
)reproduction steps for inconsistent validation
Create a directory with two files:
Perform a build that copies both files to a destination path:
Repeat the same when using a wildcard as source;
Without BuildKit, both cases produce an error (note that an error is only produced if the wildcard matches multiple files):
With BuildKit, no error is produced:
I would expect both builders to produce the same result. This error was added in moby/moby#8076 (original implementation to support multiple source in COPY/ADD). Although that PR does not mention why the error was added, I expect this was done to prevent ambiguity, and to account for the follow-up PR to implement wildcard copy.
Bug: copying multiple sources does not create directory, and overwrites destination
Now create a second file in the current directory, and repeat the build;
As can be seen in the above, BuildKit creates a file named
dest
, copiesone
to that file, and then overwrites the file with filetwo
Note that adding a trailing
/
to the destination fixes this situation;What I expected
I expected BuildKit to;
dest
should have a trailing/
if multiple sources are specifieddest
should have a trailing/
ifSRC
uses a wildcard / globbing, and matches multiple filesdest
, and to copy filesone
andtwo
into that directoryWhile
1.
and2.
could be "optional", I think we should produce an error because;/
also (see earlier example) prevents the problem of creating a file (and overwriting), which makes the error useful to havedocker cp
https://docs.docker.com/engine/reference/commandline/cp/#extended-description;If we enforce the trailing
/
for multiple files, this case would be similar to;With the exception of the "error" condition, because Docker defaults to creating the destination directory
The text was updated successfully, but these errors were encountered: