I’m using multi stage builds to create lightweight images of a C++ application.
Below a simplified example of the two Dockerfile:
First Dockerfile
FROM ubuntu:24.04 AS inter
LABEL version="Super label"
LABEL commit="abc123"
LABEL cmake.version="3.20"
RUN mkdir -p /tmp/
WORKDIR /tmp/
RUN touch first_stage.md
FROM inter AS final
LABEL project="My project"
RUN touch second_stage.md
Second Dockerfile
FROM my_test_1:latest
LABEL pipe="green"
RUN touch third_stage.md
FROM ubuntu:24.04 AS final_2
COPY --from=0 /tmp/ /tmp/
The second image is built from the first image.
How can I copy all labels from the inter_2 stage to the final_2 stage in my second Dockerfile?
I am afraid this is not going to work. You can only copy data from one stage (or image, or the build context) to your current stage.
In your case, using the my_test_1:latest image as base image for your final image doesn’t seem to make much sense, as it would inherit a lot of bloat as well.