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

  • Running a cucumber test on firefox in a docker container
  • Can't run sample express app in node container on Windows
  • Restart CMD process within cronjob
  • The relation between “docker/swarm” and “docker/swarmkit”
  • ReactJs development on docker container
  • Tensorflow on Docker: How to save the work on Jupyter notebook?
  • 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:

    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

  • Is docker commit an atomic operation?
  • Accessing external hosts from docker container
  • How to call 'docker swarm unlock' non-interactively?
  • portforwarding a node/postgres application in docker
  • Dockerfile: mkdir and COPY commands run fine but I can't see the directory and file
  • Docker cloud node BYON is unreachable
  • 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.