简体   繁体   中英

Laravel installed on a local volume (Mac) from docker nginx/php-fpm can't write session files

I have a docker-compose.yml file that runs the following (create image called mmm/nginx):

web:
 image: mmm/nginx
 ports:
 - "80:80"
 volumes:
 - ./var:/var/www
 - ./etc/nginx/sites-enabled:/etc/nginx/sites-enabled/
 links:
 - php
 - db

php:
 image: rossriley/php56-fpm
 volumes:
 - ./var:/var/www
 - ./etc/php5/php-fpm.conf:/etc/php5/fpm/php-fpm.conf
 links:
 - db

db:
 image: sameersbn/mysql
 ports:
 - "3306:3306"
 volumes:
 - /var/lib/mysql
 environment:
 - DB_NAME=tables
 - DB_USER=table
 - DB_PASS=pass

it serves up the websites nicely that are stored in /var/www

The issue happens when it tries to write to the logs and tries to write session files. While it does create the files, it can't write them.

The folder for the storage and its nested directories have the permissions set to 777 .

In order for laravel to write to them, I have to $ chmod 777 <.log|sessionfile> and it works nicely. Clearly, this is not the way to develop as I need to start new sessions regularly and create new logs daily.

How can I give laravel and the docker containers permission to write the files they create?

Update: This is what laravel's log says:

local.ERROR: exception 'ErrorException' with message 'file_put_contents(/var/www/com.mtrinteractive.sandbox.form/storage/framework/sessions/e0117b8ca17af9c19572ddb305a272b4c22bd18d): failed to open stream: Permission denied' in /var/www/com.mtrinteractive.sandbox.form/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:81

Update #2

Here's the project directory:

在此输入图像描述

Update #3

Here are the project's permissions and owners:

在此输入图像描述

在此输入图像描述

在此输入图像描述

I don't know if this help, but if your using a Dockerfile you can add

RUN usermod -u 1000 nginx

or if your using Apache you can sub. nginx for apache.

This seems to be only an issue for OS X and the issue is actually something to do with VirtualBox and not directly related to Docker. I had this issue with Docker v1.9.x and now again with v1.10.3. This time I was not able to solve it with the above solution but was able to solve it by writing my cache to a database. In this case it was MySQL/MariaDB but could have easily been memcache or redis.

Oddly, creation of log files and writing to them wasn't an issue even though the volume is mounted a separately but originated in the same folder '/Users' of my Mac.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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