Docker: Localhost didn't send any data

12,155

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.

Share:
12,155
Utkarsh Agrawal
Author by

Utkarsh Agrawal

Updated on December 23, 2022

Comments

  • Utkarsh Agrawal
    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

    Error found in docker terminal

    403 error in browser

    • Neo Anderson
      Neo Anderson over 3 years
      Can 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
      Utkarsh Agrawal over 3 years
      Hi @NeoAnderson, Please check, it was hidden earlier.
    • Gromski
      Gromski over 3 years
      Apache probably doesn't listen on port 800…!?
    • Utkarsh Agrawal
      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
      Gromski over 3 years
      As the error says, you don't appear to have any index.* file in your directory, so Apache doesn't know what to serve you for localhost:8000/.
    • Utkarsh Agrawal
      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
    Utkarsh Agrawal over 3 years
    Yes, 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
    Utkarsh Agrawal over 3 years
    Hi Neo, Just added, please check. The first screenshot was of my terminal,
  • Neo Anderson
    Neo Anderson over 3 years
    Ok, I'm trying to reproduce, but I don't have a Mac :)
  • Utkarsh Agrawal
    Utkarsh Agrawal over 3 years
    Neo, Problem is solved, as suggest by @deceze. Thanks a lot for giving the above info. :)
  • Neo Anderson
    Neo Anderson over 3 years
    Yes, got to the same answer: make sure you are copying the index under /var/www/html/
  • Utkarsh Agrawal
    Utkarsh Agrawal over 3 years
    Yes, now I understood. :)
  • Neo Anderson
    Neo Anderson over 3 years