docker elasticsearch容器不转发端口(macOs)

前端之家收集整理的这篇文章主要介绍了docker elasticsearch容器不转发端口(macOs)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个容器设置来运行elasticsearch.服务启动但我无法通过curl或浏览器连接到它.

 RUN \
 cd /tmp && \
 wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-  1.3.2.tar.gz && \
 tar xvzf elasticsearch-1.3.2.tar.gz && \
 rm -f elasticsearch-1.3.2.tar.gz && \
 mv /tmp/elasticsearch-1.3.2 /elasticsearch

 # Define mountable directories.
 VOLUME ["/data"]

 # Define default command.
  CMD ["/elasticsearch/bin/elasticsearch"]

 EXPOSE 9200
 EXPOSE 9300

连接到http:// localhost:9200不会产生任何结果. docker ps显示端口;

 0.0.0.0:49179->9200/tcp,0.0.0.0:49180->9300/tcp
 ...
 net::ERR_ADDRESS_UNREACHABLE

我错过了一些配置值吗?谢谢!

[更新]我也在run命令中尝试了-p

 docker run -i -p 9200:9200 -p 9300:9300 -t --rm -P team1/image1
最佳答案
我测试了你的Dockerfile,但它确实有效.

FROM dockerfile/java
RUN \
  cd /tmp && \
  wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.2.tar.gz && \
  tar xvzf elasticsearch-1.3.2.tar.gz && \
  rm -f elasticsearch-1.3.2.tar.gz && \
  mv /tmp/elasticsearch-1.3.2 /elasticsearch
# Define mountable directories.                                                                                    
VOLUME ["/data"]
# Define default command.                                                                                          
CMD ["/elasticsearch/bin/elasticsearch"]
EXPOSE 9200
EXPOSE 9300

我尝试构建这个Dockerfile并运行它.

$docker build -t 25312935 .
$docker run -t -p 9200:9200 -p 9300:9300 --rm 25312935
[2014-08-15 04:41:08,349][INFO ][node                     ] [Black Crow] version[1.3.2],pid[1],build[dee175d/2014-08-13T14:29:30Z]
[2014-08-15 04:41:08,349][INFO ][node                     ] [Black Crow] initializing ...
[2014-08-15 04:41:08,353][INFO ][plugins                  ] [Black Crow] loaded [],sites []
[2014-08-15 04:41:10,444][INFO ][node                     ] [Black Crow] initialized
[2014-08-15 04:41:10,444][INFO ][node                     ] [Black Crow] starting ...
[2014-08-15 04:41:10,547][INFO ][transport                ] [Black Crow] bound_address {inet[/0:0:0:0:0:0:0:0:9300]},publish_address {inet[/172.17.0.72:9300]}
[2014-08-15 04:41:10,560][INFO ][discovery                ] [Black Crow] elasticsearch/0mpczYoYSZCiAmbkxcsfpg
[2014-08-15 04:41:13,601][INFO ][cluster.service          ] [Black Crow] new_master [Black Crow][0mpczYoYSZCiAmbkxcsfpg][eeb3396b1ecc][inet[/172.17.0.72:9300]],reason: zen-disco-join (elected_as_master)
[2014-08-15 04:41:13,615][INFO ][http                     ] [Black Crow] bound_address {inet[/0:0:0:0:0:0:0:0:9200]},publish_address {inet[/172.17.0.72:9200]}
[2014-08-15 04:41:13,615][INFO ][node                     ] [Black Crow] started
[2014-08-15 04:41:13,634][INFO ][gateway                  ] [Black Crow] recovered [0] indices into cluster_state

如下所示,请求127.0.0.1:9200返回json响应.

$curl 127.0.0.1:9200
{
  "status" : 200,"name" : "Black Crow","version" : {
"number" : "1.3.2",},"tagline" : "You Know,for Search"
}

检查-p选项.这意味着将容器的端口公开给主机.如果您没有明确写入主机端口,则docker会像下面一样分配随机端口.

$docker run -t -p 9200 -p 9300 --rm 25312935
$docker ps -l
CONTAINER ID        IMAGE                COMMAND                CREATED             STATUS              PORTS                                              NAMES
1aa4c2c84d04        25312935:latest      /elasticsearch/bin/e   15 seconds ago      Up 15 seconds       0.0.0.0:49153->9200/tcp,0.0.0.0:49154->9300/tcp   sad_shockley

0.0.0.0:49153-\u0026gt;9200/tcp表示您可以通过主机的49153端口访问容器的9200端口.

$curl 127.0.0.1:49153
{
  "status" : 200,"name" : "Golem",for Search"
}

因此,如果您想使用主机9200端口,请显式写入主机端口,如-p 9200:9200或-0.0.0.0:9200:9200`

$docker ps -l
CONTAINER ID        IMAGE                COMMAND                CREATED             STATUS              PORTS                                            NAMES
eeb3396b1ecc        25312935:latest      /elasticsearch/bin/e   59 seconds ago      Up 58 seconds       0.0.0.0:9200->9200/tcp,0.0.0.0:9300->9300/tcp   high_elion

如果仍然无效,请尝试–net = host选项.您可以使用此选项在容器内使用主机网络堆栈.

$docker run -t --net=host --rm 25312935
$curl 127.0.0.1:9200
{
  "status" : 200,for Search"
}

如果两者都不起作用,我认为您需要检查其他网络配置.

猜你在找的Docker相关文章