Reputation: 680
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.
Upvotes: 2
Views: 3071
Reputation: 3090
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 :)
Upvotes: 1
Reputation: 2254
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
Upvotes: 0
Reputation: 3051
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');"
Upvotes: 4