Impossible to run a Laravel application inside a docker container due to permissions issues

I have a docker-compose configuration that defines three containers I use for one of my applications inside of an Ubuntu 16.04 instance:

  • A nginx container,
  • A mysql container,
  • And a PHP container that is slightly customised to include composer and phpunit, and is derived from a base php74:fpm-alpine directory. The working directory in this container is /var/www.

I define a single volume that maps from my application to inside the container in docker-compose.yml:

app-php:
  volumes:
    - ./src:/var/www

Whenever I try and run my Laravel application, I receive:

The stream or file "/var/www/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied.

Obviously Laravel cannot write or read to this file, but I can’t figure out why. The entire application directory has the following permissions settings:

$ la -la

-rw-rw-r--  1 myuser www-data    213 Dec 31 07:07 aFile
drwxrwsr-x 12 myuser www-data   4096 Dec 31 07:07 aDirectory

This was accomplished with the following commands:

sudo usermod -aG www-data myuser
// myuser is now a member of the www-data group.
sudo chgrp -R www-data /var/www
sudo chmod -R g+w /var/www
sudo find /var/www -type d -exec chmod 2775 {} ;
sudo find /var/www -type f -exec chmod ug+rw {} ;

None of this works. The only way I’ve been able to make my application run is my executing sudo chmod -R 777, which is not an acceptable solution. Neither 775 or 755 solve the situation.

This leads to my overall question: What alterations do I need to make, either to my docker configuration, or my permissions configuration on the host system, to have my application run?

Source: StackOverflow