New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"COPY foo/* bar/" not work if no file in foo/ #13045
Comments
OK here it is
|
How? scanning all > 800 tickets? Where is QA/ tester team of Docker? |
#dibs |
I believe this was intentional. Try:
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: 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 tried I assume you are doing @tianon do you think we should change this to a noop when source/ is empty ? If not, what would be an alternative solution for the OP ? I can think of terrible ON BUILD chains but I don't dare writing them. |
There are many ways to ignore that error in system shell. There are also checks before
Almost true. I have a base image which has a volume for future files. This volume actually has some initial files. The descendant may add some new things to that volume, or add nothing (Think, there are many applications can use this idea: nginx, apache, supervisor, mysql, php, bla bla. What I have to do now is to create an empty file
|
If we want a way to ignore errors, then I'd prefer a more generic solution that doesn't invent new sh-like stuff. For example, for a while now I thought that having |
Yeah I need that. I don't know how to make it "really need" though ;) |
No worry. I can solve the problem with Hope that's generic enough. You may close this issue. Thank you. |
We were also thinking about this the other day. What I'd like to do is provide a hook into an upstream container using ONBUILD. So something like:
However currently the COPY will always fail if the file doesn't exist (even if it's We thought about templating too but in this example each application is inheriting this container so it would be more difficult. I like the idea of a flag to ignore COPY errors. |
@mattmb that's an interesting use-case. |
Thank you @duglin and the team for your work! |
Closes moby#13045 Although its already closed for a different reason. This adds support for specifying `--ignore-error` on the COPY or ADD Dockerfile commands. I think this is an excellent example of why someone may want to not stop processing on an error: moby#13045 (comment) . Although moby#13045 itself is a good example, IMO. When there's an error on COPY or ADD we will still show the error to the user (unless -q is specified) but then we'll keep going after showing: ``` ** Ignored errors ``` unless -q is specified, then nothing is shown. Note that the temporary image ID is the same as before the bad cmd - as expected. I added this so that we can easily extend this to other commands but for now just COPY/ADD support it. Signed-off-by: Doug Davis <dug@us.ibm.com>
+1 for being able to support something like this. This is super valuable for So I'm happy to see this is being addressed. :) |
Thanks @bfirsh appreciate keeping a track on this one 👍 |
as much as I agree with keeping issues open, even if we can't work on them yet, so we don't lose track of them, I believe the current mode of operation is to close things we can't take action on. Which is why a lot of other Dockerfile/build issues have been closed. So I think we (sadly) need to close this for now. pinging @icecrime for confirmation though. |
This happens on many official images like fluend one |
+1 for the |
USER POLL The best way to get notified of updates is to use the Subscribe button on this page. Please don't use "+1" or "I have this too" comments on issues. We automatically The people listed below have upvoted this issue by leaving a +1 comment: |
What do people think about reopening #13813 (adding a ping @docker/maintainers |
it is just a bug!!!
Why can't I copy from parent directory? |
@moshebeeri This seems to be a different bug, but you can't copy files from outside the build context by design so this shouldn't work: Form Dockerfile reference:
I guess I would have expected it to complain about the src being out of the build context though. |
@moshebeeri Because it's not part of the build context. This is intentional behavior, also doesn't really seem related to this issue. side note, what you are doing in that test is a really bad idea. You never want to copy secrets into an image like that as there is no way to remove them from the resulting image. Even if you |
A Try/Catch block would solve this and will be useful for other purposes too:
|
Discussing this in the maintainers session, and we think having the |
I'm keeping this issue open, but this will be resolve if the other proposal is implemented 👍 |
|
Here is my suggestion: # syntax=docker/dockerfile:1.2
RUN --mount=type=bind,source=jars,target=/build/jars \
find /build/jars -type f -name '*.jar' -maxdepth 1 -print0 \
| xargs -0 --no-run-if-empty --replace=source cp --force source "${INSTALL_PATH}/modules/" That works around: COPY jars/*.jar "${INSTALL_PATH}/modules/" But copies no *.jar if none is found, without throwing an error. |
In my case the use of the wildcard is required because I don’t want to copy all files: $ cat Dockerfile
FROM alpine:3
COPY import/*.sql /tmp/import/
ENTRYPOINT [ "ls", "/tmp/import/" ]
$ ls import/
maybe-present.sql Readme.txt
$ docker build -t test . && docker run --rm test
[+] Building 7.5s (7/7) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 121B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/alpine:3 7.5s
=> [internal] load build context 0.0s
=> => transferring context: 69B 0.0s
=> [1/2] FROM docker.io/library/alpine:3@sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af4444c9b11 0.0s
=> => resolve docker.io/library/alpine:3@sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af4444c9b11 0.0s
=> CACHED [2/2] COPY import/*.sql /tmp/import/ 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:8f52835b04b8e0cd478156a3684d2af7f2926161dac3d873a377acfbee1f2941 0.0s
=> => naming to docker.io/library/test 0.0s
maybe-present.sql
$ rm import/maybe-present.sql
$ ls import/
Readme.txt
$ docker build -t test . && docker run --rm test
[+] Building 0.8s (6/6) FINISHED
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 121B 0.0s
=> [internal] load metadata for docker.io/library/alpine:3 0.7s
=> [internal] load build context 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [1/2] FROM docker.io/library/alpine:3@sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af44 0.0s
=> => resolve docker.io/library/alpine:3@sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af4444c9b11 0.0s
=> ERROR [2/2] COPY import/*.sql /tmp/import/ 0.0s
------
> [2/2] COPY import/*.sql /tmp/import/:
------
Dockerfile:2
--------------------
1 | FROM alpine:3
2 | >>> COPY import/*.sql /tmp/import/
3 | ENTRYPOINT [ "ls", "/tmp/import/" ]
4 |
--------------------
ERROR: failed to solve: lstat /var/lib/docker/tmp/buildkit-mount813963266/import: no such file or directory My current workaround is to remove unwanted files in an additional stage: FROM alpine:3 AS prepare-import
COPY import/ /tmp/import/
RUN find /tmp/import/ -not -name \*.sql -type f -delete
FROM alpine:3
COPY --from=prepare-import /tmp/import/ /tmp/import/
ENTRYPOINT [ "ls", "/tmp/import/" ] |
Example:
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 asON BUILD
instruction.Docker information: https://github.com/icy/docker/blob/master/bugs/volume_bug/docker.info.txt
The text was updated successfully, but these errors were encountered: