Docker: Localhost didn't send any data
The php:7.0-apache
image listens by default on port 80
. The EXPOSE
you are using in the Dockerfile
does not change that.
Normally, you have no reason to try an change the default listening port of the container, hence it has it's own IP address and you should never run into a port conflict problem.
The port election might be an issue on the host and in this regard you may chose to publish on any port that is not in use.
If you simply swap 80
and 800
in your docker run command, you shall be able to access the web-app at localhost:800
The following command will create a DNAT rule from your host machine port <src>
to the container port 80
, making it possible to visit the web-app at localhost:<src>
docker run -p <src>:80 final
Edit answering forbidden problem update:
The php:7.0-apache
image will look for an index.* under /var/www/html/
. Your Dockerfile is copying the source into /var/www/html/public
.
Utkarsh Agrawal
Updated on December 23, 2022Comments
-
Utkarsh Agrawal over 1 year
This is my Dockerfile contents:-
FROM php:7.0-apache COPY src/ /var/www/html/public VOLUME src/ /var/www/html/public EXPOSE 800
Then I run this command.
docker run -p 80:800 final
So I tried to access the localhost, but it returns 'ERR_EMPTY_RESPONSE'.
Earlier it was giving 403 error.
OS - Mac
[Edit] Adding more detail
-
Neo Anderson over 3 yearsCan you tell us what web-server are you trying to run(adding the
FROM
line missing from your Dockerfile should be enough to reproduce). -
Utkarsh Agrawal over 3 yearsHi @NeoAnderson, Please check, it was hidden earlier.
-
Gromski over 3 yearsApache probably doesn't listen on port 800…!?
-
Utkarsh Agrawal over 3 years@deceze I have tried with port 80 initially, then I run 80:80 at the terminal, but 403 error was getting.
-
Gromski over 3 yearsAs the error says, you don't appear to have any
index.*
file in your directory, so Apache doesn't know what to serve you forlocalhost:8000/
. -
Utkarsh Agrawal over 3 years@deceze Oh, now I got it. I give a search on autoindex:error and I found exactly what you caught. Thanks for informing. :)
-
-
Utkarsh Agrawal over 3 yearsYes, I did the same, I expose the port at default 80, then I run the command like you said in last, but now I am getting 403 error. I will add the screenshot above.
-
Utkarsh Agrawal over 3 yearsHi Neo, Just added, please check. The first screenshot was of my terminal,
-
Neo Anderson over 3 yearsOk, I'm trying to reproduce, but I don't have a Mac :)
-
Utkarsh Agrawal over 3 yearsNeo, Problem is solved, as suggest by @deceze. Thanks a lot for giving the above info. :)
-
Neo Anderson over 3 yearsYes, got to the same answer: make sure you are copying the index under
/var/www/html/
-
Utkarsh Agrawal over 3 yearsYes, now I understood. :)
-
Neo Anderson over 3 years