docker工人 – 无法从外部访问docker端口

所以我创build了一个新的EC2实例并在其上安装了docker。

我从( https://github.com/commonsearch/cosr-front/blob/master/INSTALL.md )部署了代码,并遵循了安装说明。

安装是成功的,我启动了服务器:

[ec2-user@ip-172-30-0-127 cosr-front]$ make docker_devserver docker run -e DOCKER_HOST --rm -v "/home/ec2-user/cosr-front:/go/src/github.com/commonsearch/cosr-front:rw" -w /go/src/github.com/commonsearch/cosr-front -p 9700:9700 -i -t commonsearch/local-front make devserver mkdir -p build go build -o build/cosr-front.bin ./server GODEBUG=gctrace=1 COSR_DEBUG=1 ./build/cosr-front.bin 2016/05/28 16:32:38 Using Docker host IP: 172.17.0.1 2016/05/28 16:32:38 Server listening on 127.0.0.1:9700 - You should open http://127.0.0.1:9700 in your browser! 

那么,现在当我想从外面访问它,我不能! 甚至不curl本地服务器。

当我运行docker ps它给了我正确的端口转发:

 [ec2-user@ip-172-30-0-127 ~]$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1a9f77e1eeb1 commonsearch/local-front "make devserver" 4 minutes ago Up 4 minutes 0.0.0.0:9700->9700/tcp stoic_hopper 9ff00fe3e70d commonsearch/local-elasticsearch-devindex "/docker-entrypoint.s" 4 minutes ago Up 4 minutes 0.0.0.0:39200->9200/tcp, 0.0.0.0:39300->9300/tcp kickass_wilson 

这些是我的docker图片:

 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE <none> <none> 3e205118cd3f 17 minutes ago 853.3 MB <none> <none> 1d233da1fa59 2 hours ago 955.7 MB debian jessie ce58426c830c 4 days ago 125.1 MB commonsearch/local-front latest 30de7ab48d43 7 weeks ago 1.024 GB commonsearch/local-elasticsearch-devindex latest b1156ada5a24 11 weeks ago 383.2 MB commonsearch/local-elasticsearch latest 808e72f49b4a 3 months ago 355.2 MB 

我尝试禁用ipv6和所有的废话谷歌提供给我,但没有成功。

有任何想法吗 ?

编辑:

另外,如果我进入前端docker集装箱(使用docker执行),那么我可以PING和CULR的前端。

但我不能从外面(也不是从我的家用电脑使用浏览器的SSH)。

也是我的docker版本:

 Client: Version: 1.9.1 API version: 1.21 Go version: go1.4.2 Git commit: a34a1d5/1.9.1 Built: OS/Arch: linux/amd64 Server: Version: 1.9.1 API version: 1.21 Go version: go1.4.2 Git commit: a34a1d5/1.9.1 Built: OS/Arch: linux/amd64 

我在github上问了一个问题,一个人救了一天。

这是他的回应:

在127.0.0.1:9700上监听的服务器你的应用程序正在监听本地主机。 本地主机的作用域是容器本身。 因此,为了能够连接到它,你将不得不在容器内。 要解决这个问题,你需要让你的应用程序在0.0.0.0上进行监听。

127.0.0.1是本地(EC2)实例的环回地址。 我刚刚按照相同的说明重新创build了问题,并在EC2实例的Docker容器中设置了服务器。

如果你打开另一个ssh会话到你的EC2实例,你可以curl环回地址,这只是吐出下面的HTML显示。

 <!DOCTYPE html><html lang="en"><head><title> Common Search </title><meta content="/apple-touch-icon-precomposed.png" itemprop="image"><link href="/favicon.ico" rel="shortcut icon"><!-- CSS: This will be replaced in templates.go:preprocessTemplate() by the inline, compiled CSS if the file build/static/css/index.css exists --><link rel="stylesheet" href="/css/global.css"/><link rel="stylesheet" href="/css/header.css"/><link rel="stylesheet" href="/css/footer.css"/><link rel="stylesheet" href="/css/hits.css"/><link rel="stylesheet" href="/css/responsive.css"/><!-- ENDCSS --><meta name="viewport" content="width=device-width, initial-scale=1"></head><body class="full"><header id="h"><div class="about"><a href="https://about.commonsearch.org/" tabindex="1">About</a></div><form id="f" action="/" method="GET" data-init="{&#34;q&#34;:&#34;&#34;,&#34;p&#34;:1,&#34;g&#34;:&#34;&#34;}"><a href="/" id="logo" tabindex="2">Common Search</a><div id="w"><div id="qw"><input id="q" name="q" type="text" size="60" value="" autofocus tabindex="3"/></div><span id="g"><select name="g" tabindex="4"><option value="ar">AR</option><option value="de">DE</option><option selected value="en">EN</option><option value="es">ES</option><option value="fr">FR</option><option value="it">IT</option><option value="ja">JA</option><option value="ko">KO</option><option value="nl">NL</option><option value="pl">PL</option><option value="pt">PT</option><option value="ru">RU</option><option value="vi">VI</option><option value="zh">ZH</option><option value="all">ALL</option></select></span><input id="s" type="submit" value="&#x1f50d;" tabindex="5"/></div></form></header><div id="hits"></div><div id="dbg"></div><div id="pager" data-page="1"></div><script src="/js/index.js" type="text/javascript"></script></body></html>