我正在嘗試對 PHP laravel 應用程式進行 dockerize。我正在使用 PHP 和作曲家圖像來實現此目的。但是,當我運行composer install時,我安裝了所有軟體包,但隨後遇到了此錯誤:
/app/vendor不存在,無法建立。
我希望 Composer 建立 /vendor 目錄!這可能是權限問題嗎?
這是我的 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
我創建了一個具有任意 ID 的用戶,因為以 root 安全身份運行composer install是一種不好的做法。
P粉4712073022024-01-02 16:30:20
我能夠透過對 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 clean && 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 # Add a new user "john" with user id 8877 RUN useradd -u 8877 john # Set working directory WORKDIR /app COPY . . RUN chmod -R 775 /app RUN chown -R john:john /app # Change to non-root privilege USER john RUN composer install --no-scripts --no-plugins