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;
}
}
Error
in the php.dockerfile file I tried to add a line to change access
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 */
I also tried to change access to the storage folder through WSL
@DESKTOP-VIGTBDU:/src/storage$ sudo chmod -R 777 .
2
Answers
You have mounted
./src:/var/www/laravel
. At that point, no changes you make to the image for the/var/www/laravel
directory matter, the container will have the files, ownership, and permission, of the files on the volume. You need to remove the volume mount or fix the access in your directories on the host (./src
directory).Most likely, you transferred your project or loaded it from a repository. The issue is not with the folder itself but with the rendered cache file. You need to clear all the cache. Start by trying
php artisan optimize
&php artisan view:clear
(view:clear might be sufficient on its own). This will delete those files, and on the next application initialization, the framework will create new files with the correct permissions.