Hasen
Hasen

Reputation: 340

Docker container published ports not accessible?

So here is the situation, I have a container running built with this dockerfile:

FROM python:2-onbuild
EXPOSE 8888
CMD [ "nohup", "mock-server", "--dir=/usr/src/app", "&" ]

I run it with this command:

 docker build -t mock_server .
 docker run -d -p 8888:8888 --name mocky mock_server

I am using it on a mac so boot2docker is going and I hit it from the boot2docker ip on 8888. I tried boot2docker ssh and hitting the container from there. I ran docker exec -it mocky bash and ps aux shows:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.9 113316 18576 ?        Ss   15:16   0:00 /usr/local/bin/python2 /usr/local/bin/mock-server --dir=/usr/src/app &
root         5  1.6  0.1  21916  3440 ?        Ss   17:52   0:00 bash
root         9  0.0  0.1  19180  2404 ?        R+   17:53   0:00 ps aux

When I cURL it:

curl -I -XGET localhost:8888/__manage
HTTP/1.1 200 OK
Content-Length: 183108
Set-Cookie: flash_msg_success=; expires=Thu, 04 Sep 2014 17:54:58 GMT; Path=/
Set-Cookie: flash_msg_error=; expires=Thu, 04 Sep 2014 17:54:58 GMT; Path=/
Server: TornadoServer/4.2.1
Etag: "efdb5b362491b8e4b8347b97ccafeca02db8d27d"
Date: Fri, 04 Sep 2015 17:54:58 GMT
Content-Type: text/html; charset=UTF-8

So I the app is running inside the container but I can't get anything from outside it. What can be done here?

Upvotes: 11

Views: 23075

Answers (2)

user1775015
user1775015

Reputation: 189

Docker runs on top of an OS and docker machine has its own ip address. One possible reason why the port is not accessible is that you are using localhost which is trying to hit 127.0.0.1: but your docker machine might be running another ip address hence by replacing the ip address your curl should work.

$ docker-machine ip default

This should give you docker machine's ip address replace it with localhost.

Upvotes: 3

Peter Lyons
Peter Lyons

Reputation: 145994

First guess is the python program is explicitly binding to the loopback IP address 127.0.0.1 which disallows any remote connections. Check the docs for that python mock tornado server for something like --bind=0.0.0.0 and adjust accordingly.

You can confirm if this is the case by doing a docker exec and in the container running netstat -ntlp | grep 8888 and seeing which IP is bound. If it's 127.0.0.1, that confirms that is indeed the problem.

Upvotes: 21

Related Questions