Docker容器中Composer搭配hirak/prestissimo并行安装失效问题
Let's figure out why the parallel installation feature of hirak/prestissimo isn't working for you in your Docker setup. I've reviewed your Dockerfile and docker-compose.yml, and here are the most likely causes along with actionable fixes:
First, Let's Recap Your Setup
Your Dockerfile builds an Ubuntu 16.04 image with PHP 7.1, installs Composer globally, adds the prestissimo plugin, and sets up Supervisor. Your docker-compose.yml mounts your local code to /app in the container.
Possible Issues & Fixes
1. Prestissimo is Installed for Root, But Not Accessible When Running Composer
All RUN commands in your Dockerfile run as root, so prestissimo gets installed in root's Composer home directory (/root/.composer). If you later run composer install as a non-root user (or even root without the correct environment variable), Composer might not pick up the global plugin.
Fix:
Add an environment variable to explicitly set the Composer home directory in your Dockerfile, so Composer always looks for global plugins in the right place:
# Add this after installing Composer ENV COMPOSER_HOME /root/.composer
2. Prestissimo Version Incompatibility with PHP 7.1
Newer versions of prestissimo drop support for PHP 7.1 (they require PHP 7.2+). The latest version you're installing likely isn't compatible with your PHP 7.1 setup.
Fix:
Install a compatible older version of prestissimo that supports PHP 7.1. Modify your global install command in the Dockerfile:
RUN composer --no-interaction global require 'hirak/prestissimo:^0.3.10'
Version 0.3.10 is the last release that works with PHP 7.1, per the package's compatibility constraints.
3. Prestissimo Didn't Install Successfully (Silent Failure)
The --no-interaction flag might be hiding installation errors. If prestissimo failed to install for some reason (like missing extensions), it won't work, but you won't see an error.
Fix:
Temporarily remove the --no-interaction flag when installing prestissimo to check for errors:
RUN composer global require 'hirak/prestissimo:^0.3.10'
After confirming the install works, you can add the flag back. You can also verify the plugin is installed by running this inside the container:
composer global show
You should see hirak/prestissimo listed in the output.
4. Volume Mounting Might Be Interfering
When you mount your local ./ directory to /app, your local composer.json or vendor folder could be overriding container settings. Also, make sure you're running composer install inside the container, not on your host machine.
Fix:
Run the command directly in the container using docker-compose:
docker-compose exec php71 composer install
Avoid mounting a local .composer directory into the container, as it will overwrite the root's Composer config where prestissimo is installed.
Updated Dockerfile Example
Here's your Dockerfile modified to address the key issues:
FROM ubuntu:16.04 RUN apt-get update && apt-get install -y software-properties-common \ && LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php \ && apt-get update \ && apt-get install -y php7.1 git vim supervisor curl unzip mysql-client wget \ && apt-get install -y --no-install-recommends php7.1-cli php7.1-dev \ php7.1-pgsql php7.1-sqlite3 php7.1-gd \ php7.1-curl php7.1-memcached \ php7.1-imap php7.1-mysql php7.1-mbstring \ php7.1-xml php7.1-imagick php7.1-zip php7.1-bcmath php7.1-soap \ php7.1-intl php7.1-readline php7.1-mcrypt php7.1-fpm RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer # Set Composer home to ensure global plugins are detected ENV COMPOSER_HOME /root/.composer # Install PHP 7.1-compatible version of prestissimo RUN composer --no-interaction global require 'hirak/prestissimo:^0.3.10' COPY docker/config/ /config/ RUN cp /config/supervisord.conf /etc/supervisor/supervisord.conf WORKDIR /app EXPOSE 9000 ENTRYPOINT ["/config/entrypoint.sh"]
Rebuild your image with this updated Dockerfile, then run composer install inside the container. You should see output indicating prestissimo is downloading packages in parallel.
内容的提问来源于stack exchange,提问作者artstyle

