[英]permission denied on laravel.log file laravel 9 using Docker
我在 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
如果您遇到錯誤:“無法以附加模式打開流或文件“/var/www/storage/logs/laravel.log”:無法打開流:權限被拒絕嘗試記錄時發生異常:”
刪除這個 laravel.log 文件。
試試這個,它可能會工作......
docker exec -it jaynesis-php bash
chmod 755 storage/ -R
這使得存儲目錄更具可寫性。
我很想知道計算機是否可以解決這些類型的問題。 這就是計算機認為的答案
解決方案是:
1. create the directory
2. add the directory to the Dockerfile
3. rebuild the image
4. run the container
所以,有點簡單,但也許您可以嘗試按照步驟操作,讓我們知道這次計算機是否正確?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.