laravel - > file_put_contents(/var/www/laravel/storage/framework/views/9f1dc9629406f3376fc417dd6985a806.php):无法打开流:权限被拒绝

问题描述 投票:0回答:1

docker-compose.yaml

version: "3.8"

services:
  nginx:
    image: "nginx:stable-alpine"
    ports:
      - "8000:80"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
      - ./src:/var/www/laravel
    depends_on:
      - php
      - mysql
  php:
    build:
      context: dockerfiles
      dockerfile: php.Dockerfile
    volumes:
      - ./src:/var/www/laravel
  mysql:
    image: mysql:8.0
    ports:
      - "3316:3306"
    env_file:
      - ./env/mysql.env
  composer:
    build:
      context: dockerfiles
      dockerfile: composer.Dockerfile
    volumes:
      - ./src:/var/www/laravel
  artisan:
    build:
      context: dockerfiles
      dockerfile: php.Dockerfile
    volumes:
      - ./src:/var/www/laravel
    entrypoint: ["php", "/var/www/laravel/artisan"]

php.Dockerfile

FROM php:8.2-fpm-alpine

WORKDIR /var/www/laravel

RUN docker-php-ext-install pdo pdo_mysql

nginx.conf

server {
    listen 80;
    index index.php index.html;
    server_name localhost;
    root /var/www/laravel/public;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

错误

在此输入图片描述

在 php.dockerfile 文件中我尝试添加一行来更改访问权限

FROM php:8.2-fpm-alpine

WORKDIR /var/www/laravel

RUN docker-php-ext-install pdo pdo_mysql

RUN chmod -R 777 /var/www/laravel/storage          /*    <------  new line   */

我还尝试通过 WSL 更改对存储文件夹的访问权限

@DESKTOP-VIGTBDU:/src/storage$ sudo chmod -R 777 .
php laravel docker permissions
1个回答
0
投票

您已安装

./src:/var/www/laravel
。此时,您无需对
/var/www/laravel
目录的映像进行任何更改,容器将拥有卷上文件的文件、所有权和权限。您需要删除卷挂载或修复主机上目录(
./src
目录)中的访问权限。

© www.soinside.com 2019 - 2024. All rights reserved.