使用Laravel&的权限被拒绝的错误码头工人 [英] Permission Denied Error using Laravel & Docker
问题描述
我有两个docker容器:Nginx和App.
该应用程序容器扩展了PHP-fpm,并具有我的Laravel代码.
I have two docker containers: Nginx and App.
The app container extends PHP-fpm and also has my Laravel Code.
在我的docker-compose.yml
中,我正在做
version: '2'
services:
nginx:
build:
context: ./nginx
dockerfile: ./Dockerfile
ports:
- "80:80"
links:
- app
app:
build:
context: ./app
dockerfile: ./Dockerfile
在我的Nginx Dockerfile中,我正在做
In my Nginx Dockerfile i'm doing:
FROM nginx:latest
WORKDIR /var/www
ADD ./nginx.conf /etc/nginx/conf.d/default.conf
ADD . /var/www
EXPOSE 80
在我的App Dockerfile中,我正在做
In my App Dockerfile I'm doing:
FROM php:7-fpm
WORKDIR /var/www
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client && docker-php-ext-install mcrypt pdo_mysql
ADD . /var/www
成功运行docker-compose后,尝试使用localhost时出现以下错误
After successfully running docker-compose up, I have the following error when I try localhost
无法打开流或文件"/var/www/storage/logs/laravel.log":打开流失败:权限被拒绝
据我了解,该存储文件夹需要Web服务器可写.
我应该怎么做才能解决这个问题?
From my understanding, the storage folder needs to writable by the webserver.
What should I be doing to resolve this?
推荐答案
使Dockerfile如下所示-
Make your Dockerfile something as below -
FROM php:7-fpm
WORKDIR /var/www
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client && docker-php-ext-install mcrypt pdo_mysql
ADD . /var/www
RUN chown -R www-data:www-data /var/www
这使目录/var/www
由www-data
拥有,而www-data
是php-fpm
的默认用户.
This makes directory /var/www
owned by www-data
which is the default user for php-fpm
.
因为它是由用户www-data
编译的.
Since it is compiled with user www-data
.
参考-
这篇关于使用Laravel&的权限被拒绝的错误码头工人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!