Below is the dockerfile that creates an image:

FROM diamol/base AS build-stage                  
RUN echo 'Building...' > /build.txt             

FROM diamol/base AS test-stage
COPY --from=build-stage /build.txt /build.txt
RUN echo 'Testing...' >> /build.txt              

FROM diamol/base
COPY --from=test-stage /build.txt /build.txt
RUN echo 'Done...' >> /build.txt               

and my understanding is, the final image consists layers of diamol/base and the layer created after the last RUN command as picture below shows: enter image description here

Is my understanding correct?


1 Answer 1


The final image will have all the layers from diamol/base as well as two additional layers - one for COPY and one for RUN command.

File /build.txt will have the following contents:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.