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

后端 未结 2 1999
醉话见心
醉话见心 2020-12-14 06:05

NOTE: I no longer use this environment so there is no way for me to test the answers and accept one. I\'m sorry.

TL;DR

相关标签:
2条回答
  • 2020-12-14 06:45

    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.*
    
    0 讨论(0)
  • 2020-12-14 06:52

    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 dependencies
    RUN 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 config
    COPY conf/nginx-site.conf /etc/nginx/sites-available/default.conf
    
    # Bundle app source 
    COPY app/ /app
    
    # Install app dependencies
    RUN 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
    }
    
    0 讨论(0)
提交回复
热议问题