Docker容器发布的端口无法访问? [英] Docker container published ports not accessible?

查看:177
本文介绍了Docker容器发布的端口无法访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这种情况下,我有一个运行在此dockerfile上的容器:

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", "&" ]

我用以下命令运行它:

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

我在Mac上使用它,所以boot2docker继续运行,我从8888的boot2docker ip上将其击中.我尝试了boot2docker ssh并从此处击中容器.我运行了 docker exec -it mocky bash ps aux 显示:

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

当我卷曲它时:

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?

推荐答案

第一个猜测是python程序已明确绑定到回送IP地址 127.0.0.1 ,该地址不允许任何远程连接.检查该python模拟龙卷风服务器的文档中是否存在-bind = 0.0.0.0 之类的内容,并进行相应的调整.

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.

您可以通过执行docker exec并在运行 netstat -ntlp |的容器中确认是否是这种情况.grep 8888 并查看绑定了哪个IP.如果它是 127.0.0.1 ,则确认确实是问题所在.

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.

这篇关于Docker容器发布的端口无法访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆