简体   繁体   English

docker php 应用程序不提供 docker 卷内的图像

[英]Images inside a docker volume are not served by a docker php application

I'm running a custom Docker image based on the official php-fpm image, with just minor tweaks.我正在运行基于官方 php-fpm 映像的自定义 Docker 映像,只需稍作调整。 Inside the host machine I have a folder containing some images I would like to server, so I am running the container and binding the host image folder to a folder in my container like /home/host/images:/var/www/storage/images .在主机内部,我有一个文件夹,其中包含一些我想要服务器的图像,因此我正在运行容器并将主机图像文件夹绑定到我的容器中的文件夹,例如/home/host/images:/var/www/storage/images This goes well and if I bash into the container I see the files there.这很顺利,如果我猛击容器,我会看到那里的文件。

My problem comes when I symlink the folder from the public folder in the container like ln -s /var/www/storage/images /var/www/public/images .当我从容器中的公共文件夹符号链接文件夹时,我的问题就出现了,比如ln -s /var/www/storage/images /var/www/public/images The link seems correct and I can navigate there using the shell and see for example my test.png image, but whenever I try to server any image for example https://my-web-app.com/images/test.png I get a 404.该链接似乎是正确的,我可以使用 shell 在那里导航并查看例如我的test.png图像,但是每当我尝试为任何图像提供服务器时,例如https://my-web-app.com/images/test.png我得到一个 404。

However, from inside the containers shell I've created another folder like /var/www/storage/images2 and then moved test.png and then updated my link like ln -s /var/www/storage/images /var/www/public/images2 and then tested https://my-wen-app.com/images/test.png and it works!但是,从容器外壳内部,我创建了另一个文件夹,如/var/www/storage/images2 ,然后移动test.png ,然后更新了我的链接,如ln -s /var/www/storage/images /var/www/public/images2然后测试https://my-wen-app.com/images/test.png并且它有效!

Why can't I link my bound folder but I can link this new folder that I just created?为什么我不能链接我绑定的文件夹,但我可以链接我刚刚创建的这个新文件夹? Is there anything else to do when binding to allow this link to work?绑定时是否还有其他事情要做以允许此链接工作?

I finally found out the cause.我终于找到了原因。 The symlink was working perfectly, the problem was that the container schema was: one container running php-fpm and another container running nginx the main folder was being bound to both containers but the images folder was just mounted to the php-fpm container so when the nginx container was asked for the images was not finding anything because it had no visibility of this volume.符号链接工作正常,问题在于容器架构是:一个容器运行php-fpm ,另一个容器运行nginx主文件夹绑定到两个容器,但图像文件夹刚刚安装到php-fpm容器,所以当nginx容器被要求提供图像没有找到任何东西,因为它没有这个卷的可见性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM