I’m trying to set up my React + Laravel application with Docker, but I’m encountering an issue while running the composer install
command inside the Docker container.
When I run docker-compose up -d --build
, the build fails at the composer install
step with the following error:
"[backend 8/9] RUN composer install –no-interaction –no-scripts –no-plugins:
#0 0.537 Composer plugins have been disabled for safety in this non-interactive session. Set COMPOSER_ALLOW_SUPERUSER=1 if you want to allow plugins to run as root/super user."
I have tried adding the COMPOSER_ALLOW_SUPERUSER=1
environment variable in various places, including in the Dockerfile, the docker-compose.yaml file, and even as a command-line argument when running docker-compose up
. However, I still encounter the same error.
Here is an example of my docker-compose.yaml file:
version: '3'
services:
backend:
build:
context: .
dockerfile: Dockerfile
environment:
- COMPOSER_ALLOW_SUPERUSER=1
volumes:
- .:/app
# other service configuration...
2
Answers
You have to change the php version in the backend Dockerfile to a newer version
If you want to use superuser for composer, you have to include
Before the composer install command in your Dockerfile.
However, a safer option is to use a non-root user such as
USER www-data
in your Dockerfile instead of superuser.