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):

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

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

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

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

  • Docker. Spring application. set & get environment variable
  • Why Docker does not destroy the hidden layers?
  • Docker: mysql:5.6 container stopping whenever a linked container is removed
  • ldapadd gives “no global superior knowledge” on default config
  • ZAP ScriptWriter synch error
  • mvn jetty:run-forked inside a docker container?
  • 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?

    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:

    enter image description here

    Update #3

    Here are the project’s permissions and owners:

    enter image description here

    enter image description here

    enter image description here

  • How can I access a shell on the VM Linux host when using the Docker Windows Beta
  • Docker Solr: Cannot index local data folder
  • Can I set Neo4j on Docker to import CSV file on the first run, not after that?
  • What is the best practices of using Docker for front end development on OS X and passthrough ENV from host to container
  • Where are Docker images stored on the host machine?
  • install linux system from docker
  • One Solution collect form web for “Laravel installed on a local volume (Mac) from docker nginx/php-fpm can't write session files”

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.