Get composer (php dependency manager) to run on a docker image build Get composer (php dependency manager) to run on a docker image build docker docker

Get composer (php dependency manager) to run on a docker image build


Installing composer like this will avoid this problem:

RUN curl -o /tmp/composer-setup.php https://getcomposer.org/installer \&& curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig \# Make sure we're installing what we think we're installing!&& php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }" \&& php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer --snapshot \&& rm -f /tmp/composer-setup.*


I ran into this problem today.

What solved it for me was to use a different directory than the one that was defined in the image.

It seems like changes that are made to the directory during build process are discarded if the directory is defined as a volume.

Here's an example of my working Dockerfile

FROM richarvey/nginx-php-fpm# Install dependenciesRUN apt-get update && \    apt-get install curl nano && \    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer# Add update nginx configCOPY conf/nginx-site.conf /etc/nginx/sites-available/default.conf# Bundle app source COPY app/ /app# Install app dependenciesRUN cd /app && \    composer install --no-interaction EXPOSE 80

And then in conf/nginx-site.conf I updated the root for my application (shortened for brevity)

server {    # ... the rest of your nginx config    root /app/public;    # ... the rest of your nginx config}