Elasticsearch错误:无法连接到localhost端口9200:连接被拒绝

问题描述 投票:2回答:2

我正在尝试使用Elasticsearch安装创建Docker镜像。我知道Elasticsearch已经拥有他的自定义Docker镜像,但我需要使用安装了Python 3.6.5的AWS Lambda函数的相同环境。所以我不得不扩展AWS Docker镜像,我必须安装Elasticsearch服务。

在这里你可以找到我的Dockerfile:

FROM lambci/lambda-base:build

ENV PATH=/var/lang/bin:$PATH \
    LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \
    AWS_EXECUTION_ENV=AWS_Lambda_python3.6 \
    PYTHONPATH=/var/runtime \
    PKG_CONFIG_PATH=/var/lang/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig

RUN rm -rf /var/runtime /var/lang && \
  curl https://lambci.s3.amazonaws.com/fs/python3.6.tgz | tar -xz -C / && \
  sed -i '/^prefix=/c\prefix=/var/lang' /var/lang/lib/pkgconfig/python-3.6.pc && \
  curl https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz | tar -xJ && \
  cd Python-3.6.8 && \
  LIBS="$LIBS -lutil -lrt" ./configure --prefix=/var/lang && \
  make -j$(getconf _NPROCESSORS_ONLN) libinstall libainstall inclinstall && \
  cd .. && \
  rm -rf Python-3.6.8

EXPOSE 9200 9300

# Add these as a separate layer as they get updated frequently
RUN pip install -U pip setuptools --no-cache-dir && \
    pip install -U virtualenv pipenv --no-cache-dir && \
    pip install -U awscli boto3 aws-sam-cli==0.10.0 aws-lambda-builders==0.1.0 --no-cache-dir && \
    yum install wget -y && \
    echo "vm.max_map_count=262144" >> /etc/sysctl.conf && \
    # I try to install elasticsearch manually
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.rpm && \
    rpm --install elasticsearch-6.6.1.rpm && \
    service elasticsearch start && \
    chkconfig --add elasticsearch && \
    sed -i -e "s/#network.host: 192.168.0.1/network.host: 127.0.0.1/g" /etc/elasticsearch/elasticsearch.yml && \
    sed -i -e "s/#http.port: 9200/http.port: 9200/g" /etc/elasticsearch/elasticsearch.yml && \
    sed -i -e "s/# Elasticsearch performs poorly when the system is swapping the memory./network.bind_host: 127.0.0.1\nnetwork.publish_host: localhost/g" /etc/elasticsearch/elasticsearch.yml

RUN service elasticsearch start && \
    service elasticsearch status && \
    service elasticsearch status

构建映像时,映像构建正确,并且elasticsearch服务正在运行。我可以看到日志:elasticsearch (pid 87) is running...。问题是我无法对http://localhost:9200进行API调用,因为它说:Failed to connect to localhost port 9200: Connection refused

我需要在容器内使用elasticsearch服务,而不是从外部使用。我究竟做错了什么?

amazon-web-services docker elasticsearch dockerfile aws-codebuild
2个回答
0
投票

您没有指明实际运行docker容器的方式。简单地暴露docker文件中的端口是不够的。您还必须使用-p选项运行。例如:

docker run -p 9200:9200 <image name here>

有关详细信息,请参阅https://docs.docker.com/engine/reference/commandline/run/


0
投票

你想要做的是使用你的应用程序的内部IP地址。这就是你如何得到它

dokku elasticsearch:info <Your elasticsearch container name here>

那你现在可以做

curl http://172.75.0.7:9200

假设您的内部IP是172.75.0.7

© www.soinside.com 2019 - 2024. All rights reserved.