I am new to Docker world. I am trying to start a laravel project in Docker but when I run docker-compose up nginx
I get this error message.
The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied
This is my docker-compose.yml
version: '3.8'
services:
nginx:
build:
context: .
dockerfile: nginx.dockerfile
ports:
- 80:80
volumes:
- ./src:/var/www/html
depends_on:
- mysql
- php
mysql:
image: mysql:5.7
ports:
- 3306:3306
environment:
MYSQL_DATABASE: laravel
MYSQL_USER: laravel
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
volumes:
- ./mysql:/var/lib/mysql
php:
build:
context: .
dockerfile: php.dockerfile
volumes:
- ./src:/var/www/html
composer:
build:
context: .
dockerfile: composer.dockerfile
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
This is my php.dockerfile
FROM php:8-fpm-alpine
ENV PHPGROUP=laravel
ENV PHPUSER=laravel
RUN adduser -g ${PHPGROUP} -s /bin/sh -D ${PHPUSER}
RUN sed -i "s/user = www-data/user = ${PHPUSER}/g" /usr/local/etc/php-fpm.d/www.conf
RUN sed -i "s/group = www-data/group = ${PHPGROUP}/g" /usr/local/etc/php-fpm.d/www.conf
RUN mkdir -p /var/www/html/public
RUN docker-php-ext-install pdo pdo_mysql
CMD ["php-fpm", "-y", "/usr/local/etc/php-fpm.conf", "-R"]
I’ve searched the internet for a solution and executed some commands but I still get the same problem.
Any idea what’s going wrong and how I can fix it?
2
Answers
I was looking for a solution for this problem for the past two days, ended up finding it on a excruciating 15 minute YouTube video that unbelievably actually got it right.
sail shell
or use the Docker containerterminal directly from its dashboard;
chown -R sail:sail storage
;This is because the user
sail
has the sameUID
of1000
as your actual Linux user, which owns the directorystorage
in your host machine.What worked for me was the following
I logged in inside the container and I removed the existing laravel.log file