如何在 docker 镜像中设置 laravel 文件权限

问题描述 投票:0回答:2

我有以下 dockerfile 来构建我的 Laravel Web 应用程序。运行它后,在尝试访问 vendorstorage 目录时出现权限错误。我的问题是为 php:7.2-fpm 基础镜像设置 Laravel 权限的正确方法是什么。我收到的错误是:

fopen(/var/www/app/vendor/dompdf/dompdf/lib/fonts/glyphicons-halflings-normal_4ced20531a4f462a8c5c535d4debd2eb.ufm): 无法打开流:权限被拒绝

Dockerfile

FROM php:7.2-fpm

WORKDIR /var/www/app

RUN apt-get update && apt-get install -y \
    build-essential \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl \
    npm

RUN curl -sL https://deb.nodesource.com/setup_9.x | bash
RUN apt-get install -y nodejs 

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-install bcmath

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Copy existing application directory contents

COPY . /var/www/app

RUN chmod -R 775 /var/www/app
RUN chmod -R 775 /var/www/app/vendor
RUN chmod -R 777 /var/www/app/storage

# COPY --from=nodeBuild ./ /var/www
RUN composer install
RUN npm install
RUN npm update

# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
laravel docker chmod chown
2个回答
0
投票

这个解决方案可能会对某人有所帮助。


-1
投票

我删除了这些命令:

RUN chmod -R 775 /var/www/app
RUN chmod -R 775 /var/www/app/vendor
RUN chmod -R 777 /var/www/app/storage

我让网络服务器递归地拥有该目录:

chown -R www-data:www-data /var/www

问题就这样解决了

© www.soinside.com 2019 - 2024. All rights reserved.