gpt4 book ai didi

amazon-web-services - Elasticsearch错误:无法连接到本地主机端口9200:连接被拒绝

转载 作者:行者123 更新时间:2023-12-02 18:36:41 26 4
gpt4 key购买 nike

我正在尝试创建安装了Elasticsearch的Docker镜像。我知道Elasticsearch已经有他的自定义Docker镜像,但是我需要使用安装了Python 3.6.5的AWS Lambda Function的相同环境。因此,我必须扩展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服务。我究竟做错了什么?

最佳答案

您没有指出您实际如何运行docker容器。仅在docker文件中公开端口是不够的。您还必须使用-p选项运行。例如:

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

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

关于amazon-web-services - Elasticsearch错误:无法连接到本地主机端口9200:连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55048589/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com