The Problem:
"Composer plugins disabled in Docker: Set COMPOSER_ALLOW_SUPERUSER=1 to enable plugins" error while running composer install
inside a Docker container. Despite adding the COMPOSER_ALLOW_SUPERUSER=1
environment variable in the Dockerfile, docker-compose.yaml file, and as a command-line argument, the error persists.
The Solutions:
Solution 1: Set Composer Superuser Permission
To enable Composer plugins within a Docker environment, set the environment variable COMPOSER_ALLOW_SUPERUSER
to 1
within the Dockerfile before running the composer install
command. This grants superuser privileges to Composer, allowing it to run plugins successfully.
Dockerfile with Composer Superuser Permission:
...
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN composer install --no-interaction --no-scripts --no-plugins
...
Alternatively, for security concerns, consider using a non-root user for Composer operations by adding the following line before RUN composer install
:
USER www-data
Q&A
How to solve the error of docker plugins disabled in docker for PHP?
Include ENV COMPOSER_ALLOW_SUPERUSER=1 before the composer install command in your Dockerfile.
A safer solution is available for the docker plugins disabled problem?
Yes, using a non-root user such as USER www-data instead of superuser.