Permission Denied Error using Laravel & Docker Permission Denied Error using Laravel & Docker nginx nginx

Permission Denied Error using Laravel & Docker


Make your Dockerfile something as below -

FROM php:7-fpmWORKDIR /var/wwwRUN apt-get update && apt-get install -y libmcrypt-dev mysql-client && docker-php-ext-install mcrypt pdo_mysqlADD . /var/wwwRUN chown -R www-data:www-data /var/www

This makes directory /var/www owned by www-data which is the default user for php-fpm.

Since it is compiled with user www-data.

Ref-

https://github.com/docker-library/php/blob/57b41cfc2d1e07acab2e60d59a0cb19d83056fc1/7.0/jessie/fpm/Dockerfile


I found similar problem and I fixed it by

chown -R www-data:www-data /var/wwwchmod -R 755 /var/www/storage


When using bind mounts in Docker, the original permissions in the Docker host are preserved in the container. This enables us to set appropriate permissions on the Docker host, to be used inside the container.

First, you should find the uid and gid of the nginx, for example:

docker-compose exec nginx id www-data

The output of this command would be something like this:

uid=33(www-data) gid=33(www-data) groups=33(www-data)

Then, you should use these uid and gid to set permissions on Docker host, which will be used by the container too. So, run the following command on the Docker host:

sudo chown -R 33:33 site

Now everything must be working.