php - How to copy from one image to another in a docker multistaged build?

one text

Solution:

You have to alias the image as otherwise docker uses the base image as provided by composer and not the image you built.

This means you need to change your FROM statement:

FROM composer as BUILDER

and reference your image:

COPY --from=BUILDER /tmp/composer-vendors/vendor ./vendor

The alias could be anything, I used BUILDER as an example. In fact, you could even reuse the name:

FROM composer AS composer

though that might lead to unexpected behavior if people are not expecting a modified image.

Source