Laravel Docker and permissions on shared volumes

So I’ve been using Docker for quite a long time. Because I’ve switched over development to using Docker, I recently made the decision to switch to Windows 10 from Mac OS, right before Mac announced 32GB RAM laptops. Anyway, I am beginning to doubt this decision, even though 99% of stuff has been working well. I have been doing all my development on /d/ drive in WSL Ubuntu and Windows PHPStorm, and running everything in docker using PHP, Nginx, MySQL, Redis all container linked and volume shared with persistence.

Occasionally, and only on certain functions, my PHP 7.2 Laravel apps will throw a 500 error because it cannot write to the log. Here and here are some stack overflow posts regarding permissions on Laravel in Docker.

The strange thing is for me, 99% of the time, my file shared code works perfectly fine, I can tail the log in host Windows, in WSL Ubuntu, or inside the container too. Occaisonally though, this breaks down, and Laravel complains that

UnexpectedValueException: The stream or file "/Projects/laravel-app/storage/logs/laravel.log" could not be opened: failed to open stream: No such file or directory in file /Projects/l;aravel-app/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107\n
Stack trace:\n
1. UnexpectedValueException->() /Projects/interceptor-app/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107\n

Now the really frustrating thing here is that my colleagues are able to run the same exact thing on Mac and Mac docker just fine. It’s specifically an issue with Docker for Windows.

Also, as you already know, all the advice on the internet that suggests to chmod 0777 storage has no effect on a shared volume.

The one workaround I have seen is to not use a shared volume, but to build the container and copy and chmod the files into it, but that is time prohibitive for development.

Is there any other solution to this problem?

1 Like