docker 暴露端口 查看_在Ubuntu中无法访问Docker的暴露端口

The Sinatra web app I created works inside the container and I am able to access it at 9393 within the container. Following is my Dockerfile (which uses the image specified by the Dockerfile: jikkujose/red):

FROM jikkujose/red

MAINTAINER Jikku Jose

COPY . /banana_app

WORKDIR /banana_app

RUN bundle install

EXPOSE 9393

ENTRYPOINT ["bundle", "exec", "shotgun"]

I launched the built image by, docker run -itdP hey

When I do, 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

When I do, 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: I have specified to bind the app to 0.0.0.0.

What am I missing? Why can't I access the app at the host too?

解决方案

Did you solve this? I'm having the same problem - in my case for port 80. For the time being, I've worked around it by using the ip address of the docker host instead of referencing localhost. I'm getting this using /sbin/ifconfig on interface docker0.

Ie:

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

Then

curl http://${DOCKER_HOST_IP} gives me the expected result whereas curl http://localhost fails.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值