问题描述
我具有以下dockerfile来构建我的Laravel Web应用程序。运行它后,尝试访问供应商和存储目录时出现权限错误。我的问题是为PHP:7.2-fpm基本映像设置Laravel权限的正确方法是什么。我收到的错误是:
打开(/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"]
解决方法
我删除了以下命令:
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
这解决了问题