Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access container's web server on localhost:80

I can't access container's web server on localhost:80 however I can access the webserver on 127.0.0.1:80.

What am I doing wrong?

I have docker Version 1.12.2-rc1-beta27 (build: 12496) installed on a Mac.

I ran a container with the command docker run -d -p 80:80 training/webapp python app.py.

The container has the following properties

$docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                  NAMES
baaf4676e548        training/webapp     "python app.py"     22 minutes ago      Up 22 minutes       0.0.0.0:80->5000/tcp   big_volhard

My understanding was I should be able to access the website from localhost:80.

This does not work. I get the error message

Could not get any response

I know that I am using Docker for Mac as I've ran the command env | grep DOCKER and it returns no output.

First update: My /etc/hosts looks like:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

Second update: I've also noticed that when I run the containers using command docker run -d -P training/webapp python app.py, then localhost:autoGeneratedPortNumber works.

Now I'm not sure why both commands (which are more or less the same, the only difference being in one the port number is being specified) have different effects.

like image 581
breaktop Avatar asked Nov 09 '22 07:11

breaktop


1 Answers

In your server file, instead of listening your server at 127.0.0.1 (localhost), listen at 0.0.0.0 which means that your server will now listen to any available network interface. I was making this mistake, but after changing it , it worked great.

like image 95
Nitish Chauhan Avatar answered Nov 15 '22 06:11

Nitish Chauhan