Categories: php, image, apache, docker, localhost

Can't access images in docker php image

1 answer

I got a small PHP website with some js and wanted to run it with docker. Because it's a gallery, it has images in a subfolder. The main index.php runs fine, except no images are found. I looked inside the folder with the normal docker CLI and an 'echo ls ...', but everything is in there. If I go to localhost:8080/images, I get the Error 403 (consol print bellow).

The Images are loaded via php, which generates paths like: '/var/www/html/images/2555-P160-05.jpg'. Are they maybe wrong?


Solution: I got the wrong paths. I'm now getting the pathname via

$link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?                  "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .                   $_SERVER['REQUEST_URI'];  

instead of getcwd(). The comments reminded me to check the images directly and not the entire folder. I also edited the Dockerfile and removed the permission changes.


OS: Ubuntu 19.04 Docker -v: 19.03.6

Here are my latest edits:

docker-compose.yml:

version:  '3' services:   photography-website:     build:        context: ./       dockerfile: ./     ports:       - 8080:80     volumes:       - .:/var/www/html 

Dockerfile:

FROM php:7.4.4-apache 

Error 403:

172.18.0.1 - - [06/Apr/2020:23:19:48 +0000] "GET /images/ HTTP/1.1" 403 493 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0" 

Thanks for reading.

All answers to this question, which has the identifier 61070572

The best answer:

Paths should be localhost:8080/images/[image].jpg not var/www/html/images/[image].jpg.

More info in my post above.

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data