我在docker容器中使用composer安装了laravel,然而,当我试图访问索引页时,我得到了这个错误
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:
我正在使用laravel 9,我已经尝试了所有可能的解决方案,我能找到,它不起作用。我用的是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
试一试,它可能会成功…
docker exec -it jaynesis-php bash
chmod 755 storage/ -R
这使得存储目录更可写。
如果出现错误:"流或文件"/var/www/storage/logs/laravel.log"无法以追加模式打开:打开流失败:拒绝权限尝试记录时发生异常:">
删除laravel.log文件