Images inside a docker volume are not served by a docker php application-ThrowExceptions

Exception or error:

I’m running a custom Docker image based on the official php-fpm image, with just minor tweaks. 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. 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.
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.

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!

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?

How to solve:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *