无法在Ubuntu中访问Docker的暴露端口

我创build的Sinatra Web应用程序在容器工作,我可以在容器内的9393访问它。 以下是我的Dockerfile (使用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启动了build立的映像

当我这样做的时候, 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:我已经指定将应用绑定到0.0.0.0

我错过了什么? 为什么我不能在主机上访问应用程序呢?

你解决了吗? 我有同样的问题 – 在我的情况下端口80.目前,我已经通过使用泊坞窗主机的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失败。