skip to Main Content

I’m following the Laravel documentation for using Laravel with Docker with using the Getting Started section: https://laravel.com/docs/9.x/installation#getting-started-on-macos. I use this curl command: curl -s "https://laravel.build/example-app" | bash to create the project and then I run sail up to create the docker containers, which works fine.

The issue happens when I come to work with the storage folder. I’m following this documentation: https://laravel.com/docs/9.x/filesystem#the-public-disk. I run php artisan storage:link which creates this item in the links array:

'links' => [
        public_path('storage') => storage_path('app/public'),
    ],

However, when I go to localhost and try and retrieve an asset by just entering the URL, I get a 404 error. I went into the docker container to see if the symlink was actually created. This is the output: lrwxr-xr-x 1 root root 79 Dec 28 11:29 storage -> /Users/ex_user/example-app/storage/app/public. It points to my local storage directory, so I ran php artisan storage:link inside of the container and the output of the alias was this: lrwxr-xr-x 1 root root 32 Dec 28 11:47 storage -> /var/www/html/storage/app/public. The images then load correctly. So how can I solve this without have to run the command within the docker container, I do want the project to be able to work if somebody wants to run it without the docker container. I haven’t changed anything with my project, this is a fresh pull from the Laravel CURL request so I don’t know if this is a bug that needs to be fixed. Any ideas on how to fix this? Thanks

I’ve tried changing the paths and creating a symlink within the container, but this is not the optimal solution

2

Answers


  1. If you run the storage: link from outside of your container, the symlink will be relative to your local machine. Get into the container by running: docker exec -it name_of_your_php_container bashes

    Login or Signup to reply.
  2. The command php artisan storage:link creates absolute symbolic links by default.

    To create relative symbolic links instead, use php artisan storage:link --relative. This requires that the symfony/filesystem dependency is installed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search