laravel.log文件laravel 9使用Docker拒绝许可
我在Docker容器内部使用Composer安装了Laravel,但是,当我尝试访问使用Laravel 9的索引页面时,我会遇到此错误
The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log:
,我尝试了所有可能找到的解决方案,并且它不起作用。 我在Windows 10上运行。
这是我的Dockerfile,
FROM php:8.0.2-fpm
# Install dependencies for the operating system software
RUN apt-get update && apt-get install -y \
git \
curl \
zip \
unzip
# Install extensions for php
RUN docker-php-ext-install pdo_mysql
# Install composer (php package manager)
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Set working directory
WORKDIR /var/www
我将以下代码添加到我的Dockerfile,
# Assign permissions of the working directory to the www-data user
RUN chown -R www-data:www-data \
/var/www/storage \
/var/www/bootstrap/cache
但是当尝试使用其中的代码再次构建图像时,我会收到一条错误消息。
目录不存在
是我的docker-compose.yml文件
version: '3.8'
services:
php:
build:
context: ./
dockerfile: Dockerfile
container_name: jaynesis-php
restart: always
working_dir: /var/www
volumes:
- ../src:/var/www
nginx:
image: nginx:latest
container_name: jaynesis-nginx
restart: always
ports:
- "8000:80"
volumes:
- ../src:/var/www
- ./nginx:/etc/nginx/conf.d
mysql:
container_name: jaynesis-db
image: mysql:8.0
volumes:
- ./storage/mysql:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
I installed laravel using composer inside of my docker container, however, i get this error when i try to access the index page
The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log:
I am using laravel 9, i have tried all possible solution i could find and it doesn't work.
I run on windows 10.
Here is my Dockerfile
FROM php:8.0.2-fpm
# Install dependencies for the operating system software
RUN apt-get update && apt-get install -y \
git \
curl \
zip \
unzip
# Install extensions for php
RUN docker-php-ext-install pdo_mysql
# Install composer (php package manager)
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Set working directory
WORKDIR /var/www
I have adding the below code to my Dockerfile
# Assign permissions of the working directory to the www-data user
RUN chown -R www-data:www-data \
/var/www/storage \
/var/www/bootstrap/cache
but when try to build the image again with the code in it, i get an error message saying
directory doesn't exist
Here is my docker-compose.yml file
version: '3.8'
services:
php:
build:
context: ./
dockerfile: Dockerfile
container_name: jaynesis-php
restart: always
working_dir: /var/www
volumes:
- ../src:/var/www
nginx:
image: nginx:latest
container_name: jaynesis-nginx
restart: always
ports:
- "8000:80"
volumes:
- ../src:/var/www
- ./nginx:/etc/nginx/conf.d
mysql:
container_name: jaynesis-db
image: mysql:8.0
volumes:
- ./storage/mysql:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试一试,它可能会起作用...
这使存储目录更具写作。
Give this a go, it might work...
This makes the storage directory a little more writeable.
如果您有错误:“流或文件”/“ var/www/storage/logs/laravel.log”无法在附录模式下打开:未能打开流:尝试登录时发生的例外情况
:这个laravel.log文件。
If you have an error: "The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log:"
Delete this laravel.log file.