无法在Ubuntu中访问Docker的公开端口

时间:2015-11-12 08:49:32

标签: ruby docker sinatra

我创建的Sinatra web app在容器内 ,我可以在容器内的9393访问它。以下是我的Dockerfile(使用Dockerfile指定的图片:jikkujose/red):

FROM jikkujose/red
MAINTAINER Jikku Jose <jikkujose@gmail.com>

COPY . /banana_app
WORKDIR /banana_app

RUN bundle install
EXPOSE 9393
ENTRYPOINT ["bundle", "exec", "shotgun"]

我按docker run -itdP hey

推出了构建的图片

当我这样做时,docker ps -a

CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                     NAMES
a815e2852c68        hey                 "bundle exec shotgun   13 minutes ago      Up 13 minutes       0.0.0.0:32783->9393/tcp   cranky_rosalind

当我这样做时,curl -v 'http://localhost:32783'

* Rebuilt URL to: http://localhost:32783/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 32783 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:32783
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

PS:我have specified将应用绑定到0.0.0.0

我错过了什么?为什么我也无法在主机上访问应用程序?

1 个答案:

答案 0 :(得分:1)

你解决了吗?我遇到了同样的问题 - 在我的情况下是80端口。目前,我通过使用docker主机的ip地址而不是引用localhost解决了这个问题。我在接口docker0上使用/ sbin / ifconfig获取此信息。

即:

DOCKER_HOST_IP=`/sbin/ifconfig docker0 | /bin/grep "inet addr" | /bin/cut -d: -f2 | /bin/awk '{print $1}'`

然后

curl http://${DOCKER_HOST_IP}给出了预期的结果,而curl http://localhost失败了。