How to install PHP composer inside a docker container How to install PHP composer inside a docker container docker docker

How to install PHP composer inside a docker container


In Dockerfile :

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer


I can install composer adding this line on my test dockerfile:

# Install ComposerRUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

Here is the dockerfile:

FROM php:7.1.3-fpmRUN apt-get update && apt-get install -y libmcrypt-dev \    mysql-client libmagickwand-dev --no-install-recommends \    && pecl install imagick \    && docker-php-ext-enable imagick \&& docker-php-ext-install mcrypt pdo_mysql# Install ComposerRUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

It works for me, to test if the composer are installed i access to my container bash and execute:

composer --versionComposer version 1.6.5 2018-05-04 11:44:59


Create an executable of your composer file using

RUN curl -sS https://getcomposer.org/installer | php -- \--install-dir=/usr/bin --filename=composer && chmod +x /usr/bin/composer