Adding Composer to PHP docker images using multi-stage builds

# start with the official Composer image and name it
FROM
composer:1.9.3 AS composer

# continue with the official PHP image
FROM
php:7.4.2

# copy the Composer PHAR from the Composer image into the PHP image
COPY --
from=composer /usr/bin/composer /usr/bin/composer

# show that both Composer and PHP run as expected
RUN
composer --version && php -v
# use the official PHP image as base image
FROM
php:7.4.2
# copy the Composer PHAR from the Composer image into the PHP image
COPY --
from=composer:1.9.3 /usr/bin/composer /usr/bin/composer
# show that both Composer and PHP run as expected
RUN
composer --version && php -v
ENV COMPOSER_ALLOW_SUPERUSER 1 

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store