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
Multiple COPY statements in one layer is not possible #33551
Comments
Suppose I have a Dockerfile like so: FROM busybox AS main
RUN mkdir /test
WORKDIR /test
RUN let i=0; while true; do touch test$i; let i=i+1; if [ $i -eq 5 ]; then exit 0; fi; done
RUN let i=0; while true; do touch other$i; let i=i+1; if [ $i -eq 5 ]; then exit 0; fi; done
RUN ls -lh /test
FROM busybox
RUN mkdir /test
COPY --from=main /test/test* /test/
RUN ls -lh /test The last line in the
The last line of the Dockerfile lists all the files in
Does this work for you? |
Thanks for your proposal. Unfortunately it does not work for me, since I don't suppose anything about the multiple files that I copy: they do not necessarily share the same prefix, the same extension or the same directory. It was probably unclear in the example that I gave you, sorry for that. |
@loicgelle In this case, I'd recommend grouping the files in the |
@cpuguy83 I also considered this alternative option. But I think it is more like a workaround than a real long-term solution, for various reasons:
|
I think the proposal for FROM busybox AS builder
RUN (steps that are done during the build stage)
FROM busybox
# Mount the image from "builder" stage at `/artifacts` during this run
RUN --mount=src=/,dest=/artifacts,from=builder \
cp /artifacts/usr/include/header_1.h /usr/include/header_1.h \
&& cp /artifacts/usr/include/header_n.h /usr/include/header_n.h |
@thaJeztah Thanks for your reply. Thing is I have no "cp" command during the last stage of the build since I start from scratch. Once again, I think that what could be done in terms of primitive operations (like |
@cpuguy83 @thaJeztah I really believe that operations like |
Sorry for my late reply, I missed the part about I see what you're asking, but really not sure we should add too much options to the Additional features were added (e.g. Likewise, the
While having multiple copy statements may be a limited scope change, it may be a sliding slope, people will demand more ("wildcards are broken", "cannot use Although the For your situation, I think the build can be seen as three stages;
Which translates to something like: FROM busybox AS builder
RUN (steps that are done during the build stage)
FROM busybox AS stage2
# Mount the image from "builder" stage at `/artifacts` during this run
RUN --mount=src=/,dest=/artifacts,from=builder \
cp /artifacts/usr/include/header_1.h /release/usr/include/header_1.h \
&& cp /artifacts/usr/include/header_n.h /release/usr/include/header_n.h \
&& chown -r 123:456
# Multiple copy statements also should not be an issue in this stage
COPY --from=foo /usr/include/header_1.h /release/usr/include/header_1.h
COPY --from=foo /usr/include/header_n.h /release/usr/include/header_n.h
# Package
FROM scratch
COPY --mount=src=/release,dest=/release,from=stage2 \
cp -r /release / |
@thaJeztah Looks like a good compromise! Thank you for your help, that closes the issue for me. I still think that there should be a more flexible way of "exporting/importing" build artifacts between images, but this is more related to #32868 |
@loicgelle thanks! Yes, more improvements are coming, and don't hesitate to open issues if you have suggestions for improvement. We can still reconsider changes in future, but with the changes mentioned in my comment, we expect many use cases will be covered. |
There were some typos in the suggestion by @thaJeztah This worked for me, so for further reference: FROM busybox AS builder
RUN (steps that are done during the build stage)
FROM busybox AS stage2
# Mount the image from "builder" stage at `/artifacts` during this run
RUN --mount=src=/,dst=/artifacts,from=builder \
cp /artifacts/usr/include/header_1.h /release/usr/include/header_1.h \
&& cp /artifacts/usr/include/header_n.h /release/usr/include/header_n.h \
&& chown -r 123:456
# Multiple copy statements also should not be an issue in this stage
COPY --from=foo /usr/include/header_1.h /release/usr/include/header_1.h
COPY --from=foo /usr/include/header_n.h /release/usr/include/header_n.h
# Package
FROM scratch
RUN --mount=src=/release,dst=/release,from=stage2 \
cp -r /release/* / |
Hello all,
This issue because I am facing a problem that cannot be solved using the current features in Docker Edge. I am trying to use the new multi-stage build capabilities of Docker Edge to build complex software and I want a fine-grained way to extract files from that build.
For tracing purposes, I need to know exactly what is the output of my build. So supposing I want to extract a few headers files that I get from the build, this is not a satisfying solution:
COPY --from=foo /usr/include /usr/include
because I want to be able to do:
Of course the problem of this solution is twofold: it will create unnecessary layers, and it makes the build fails when Docker considers that the Dockerfile has too many statements.
It would be nice to have a way to perform a copy that is sematically equivalent to:
In my case, precising the destination is even unnecessary because I want to replicate the directory structure created by previous build stages. Maybe an instruction tuple like
EXPORT
/IMPORT
would be more convenient for these use cases.The text was updated successfully, but these errors were encountered: