laravel / sail

Docker files for running a basic Laravel application.
https://laravel.com/docs/sail
MIT License
1.69k stars 477 forks source link

Storage folder write permissions fail on newly installed Sail #81

Closed cyrrill closed 3 years ago

cyrrill commented 3 years ago

Description:

Unable to write to storage folder.

image

Steps To Reproduce:

I have installed Sail into an existing Laravel 8 application as per the installation guide. The container and associated services come up and yield no errors.

image

When I attempt to access the application from the browser, the exception mentioned above shows up.

Normally, all you need to do is chmod and/or chown the /storage/ folder in order for Laravel to run.

When I try to publish the Dockerfiles (in order to attempt to set permissions), I get this other exception:

 ./vendor/bin/sail artisan sail:publish -vvv

   League\Flysystem\Exception 

  Impossible to create the root directory "/var/www/html/docker/7.4".

  at vendor/league/flysystem/src/Adapter/Local.php:112
    108▕             clearstatcache(false, $root);
    109▕ 
    110▕             if ( ! is_dir($root)) {
    111▕                 $errorMessage = isset($mkdirError['message']) ? $mkdirError['message'] : '';
  ➜ 112▕                 throw new Exception(sprintf('Impossible to create the root directory "%s". %s', $root, $errorMessage));
    113▕             }
    114▕         }
    115▕     }
    116▕ 

  1   vendor/league/flysystem/src/Adapter/Local.php:133
      League\Flysystem\Adapter\Local::ensureDirectory()

  2   vendor/league/flysystem/src/Filesystem.php:102
      League\Flysystem\Adapter\Local::write()

  3   vendor/league/flysystem/src/MountManager.php:597
      League\Flysystem\Filesystem::put()

  4   vendor/laravel/framework/src/Illuminate/Foundation/Console/VendorPublishCommand.php:254
      League\Flysystem\MountManager::put()

  5   vendor/laravel/framework/src/Illuminate/Foundation/Console/VendorPublishCommand.php:238
      Illuminate\Foundation\Console\VendorPublishCommand::moveManagedFiles()

  6   vendor/laravel/framework/src/Illuminate/Foundation/Console/VendorPublishCommand.php:203
      Illuminate\Foundation\Console\VendorPublishCommand::publishDirectory()

  7   vendor/laravel/framework/src/Illuminate/Foundation/Console/VendorPublishCommand.php:166
      Illuminate\Foundation\Console\VendorPublishCommand::publishItem()

(...)
Tom-NSN commented 3 weeks ago

Hello ! I did find a workaround that seem to works for docker desktop on linux In the Dockerfile i changed the creation line of the user for this

RUN useradd -ms /bin/bash --no-user-group -o -g $WWWGROUP -u $WWWUSER sail

And i set WWWGROUP and WWWUSER to 0:0 So it will alias sail for the root user but binded to a non-root user on your computer

RyanPaiva56 commented 3 weeks ago

I'm able to reproduce this on a fresh install of Ubuntu 22.04.5 LTS, a fresh install of the latest version of Laravel, and a fresh install of Docker Desktop.

Running docker context use default, restarting, and running sail build --no-cache does not resolve the issue.

From looking into this, the issue could be solved on Laravel's side by making sure that the user has proper access permission when the container is built. On Docker's side, there's something about Docker Desktop that makes this change necessary.

https://github.com/docker/desktop-linux/issues/252

If someone familiar with Sail wants to point me in the right direction, I'm happy to make a pull request to resolve.