Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: Localhost didn't send any data [closed]

Tags:

docker

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

Error found in docker terminal

403 error in browser

like image 350
Utkarsh Agrawal Avatar asked Oct 14 '25 15:10

Utkarsh Agrawal


1 Answers

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.

like image 90
Neo Anderson Avatar answered Oct 17 '25 04:10

Neo Anderson