繁体   English   中英

laravel.log 文件 laravel 9 使用 Docker 的权限被拒绝

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM