存储符号链接,指向docker容器的本地存储目录



我遵循Laravel文档使用Laravel与Docker使用入门部分:https://laravel.com/docs/9.x/installation#getting-started-on-macos。我使用curl命令:curl -s "https://laravel.build/example-app" | bash来创建项目,然后我运行sail up来创建docker容器,这很好。

当我开始使用存储文件夹时,问题就发生了。我遵循这个文档:https://laravel.com/docs/9.x/filesystem#the-public-disk。我运行php artisan storage:link,在链接数组中创建这个项目:

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

然而,当我去到localhost并尝试通过输入URL检索资产时,我得到一个404错误。我进入docker容器,看看是否真的创建了符号链接。这是输出:lrwxr-xr-x 1 root root 79 Dec 28 11:29 storage -> /Users/ex_user/example-app/storage/app/public。它指向我的本地存储目录,所以我在容器内运行php artisan storage:link,别名的输出是这样的:lrwxr-xr-x 1 root root 32 Dec 28 11:47 storage -> /var/www/html/storage/app/public。然后正确加载图像。所以我怎么能解决这个问题,而不必在docker容器内运行命令,我确实希望这个项目能够工作,如果有人想在没有docker容器的情况下运行它。我没有改变我的项目的任何东西,这是从Laravel CURL请求的新拉,所以我不知道这是否是一个需要修复的bug。对如何解决这个问题有什么想法吗?由于

我试过改变路径,并在容器内创建一个符号链接,但这不是最优的解决方案

命令php artisan storage:link默认创建绝对符号链接。

要创建相对符号链接,请使用php artisan storage:link --relative。这需要安装symfony/filesystem依赖。

如果从容器外部运行storage: link,则符号链接将相对于本地计算机。执行以下命令进入容器:docker exec -it name_of_your_php_container bash

最新更新