I'm trying to dockerize a PHP laravel application. I'm using PHP and composer images to achieve this. However, when I run composer install, I install all the packages but then get this error:
/app/vendor does not exist and cannot be created.
I want Composer to create the /vendor directory! Could this be a permissions issue?
This is my Dockerfile:
FROM php:7.4.3-cli # Install system dependencies RUN apt-get update && apt-get install -y git curl libpng-dev libonig-dev libxml2-dev zip unzip # Clear cache RUN apt-get cl ean && rm -rf /var/lib/apt/lists/* # Install PHP extensions RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd COPY --from=composer:2.4.4 /usr/bin/composer /usr/local/bin/composer # Set working directory WORKDIR /app COPY . . # Add a new user "john" with user id 8877 RUN useradd -u 8877 john # Change to non-root privilege USER john RUN composer install
I created a user with an arbitrary ID because running composer install as root security is a bad practice.
I was able to resolve the issue by making some changes to the Dockerfile: