2

I want to be able to use composer install inside my php-fpm container. My current setup:

docker-compose.yml

version: '2'

services:
    web:
        image: nginx
        ports:
          - "80:80"
        volumes:
          - ./public:/var/www/html
          - ./vhost.conf:/etc/nginx/conf.d/vhost.conf

    fpm:
        image: php:fpm
        volumes:
          - ./public:/var/www/html
        expose:
          - 9000

    composer:
        restart: 'no'
        image: composer/composer
        command: install --working-dir=/var/www/html
        volumes_from:
          - fpm

But obviously my command: install is happening in the composer container and doesnt have the required php extensions to complete the install.

And composer install inside php-fpm container says composer is not installed

Somehow google doesn't have an answer for this from what I have seen.

3 Answers 3

4

You just need to install composer inside your fpm container.

Something like

FROM php:5.6-fpm 

...
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
    && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
    && php -r "unlink('composer-setup.php');"
Sign up to request clarification or add additional context in comments.

Comments

1

A more sexy way yo add composer into your image :

# Install Composer
ADD https://getcomposer.org/installer /tmp/composer-setup.php
RUN php /tmp/composer-setup.php --install-dir /usr/local/bin/ --filename composer \
 && rm /tmp/composer-setup.php

Note that composer can be useful for development images (eg: For Continuous Integration or tests). A production image should not have composer inside... Only the generated vendors :)

Comments

0

Actually what I would suggest would be a separate lightweight php-cli container just to run composer (and other commands). It doesn't have to run a "persistent" way. If interested have a look how I did my image for running php tasks like composer or phpunit.

docker run -ti --rm -v /path/to/your/project:/app kmwrona/ci-stack /usr/bin/composer install --quiet
docker run -ti --rm -v /path/to/your/project:/app kmwrona/ci-stack /usr/bin/composer dump-autoload --optimize
docker run -ti -a STDOUT -v /path/to/your/project:/app kmwrona/ci-stack /usr/bin/phpunit --log-junit /app/junit.xml --testdox-html /app/unit-tests-html-report.html

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.