Can't access Docker's exposed port in Ubuntu

允我心安 提交于 2019-12-22 11:35:13

问题


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 <jikkujose@gmail.com>

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?


回答1:


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.



来源:https://stackoverflow.com/questions/33667467/cant-access-dockers-exposed-port-in-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!