gpt4 book ai didi

docker - 无法启动 Elasticsearch ,因为找不到JAVA_HOME

转载 作者:行者123 更新时间:2023-12-02 19:56:26 33 4
gpt4 key购买 nike

我正在使用docker compose来旋转两个 flex 搜索服务。所以我有一个名为elasticsearch.yml的文件。我使用命令执行文件(docker-compose -f src / main / docker / elasticsearch.yml up)。但是,当我运行第二项服务elasticsearch2时,出现错误。

Building elasticsearch2
Step 1/5 : FROM docker.elastic.co/elasticsearch/elasticsearch:6.6.1
---> c6ffcb0ee97e
Step 2/5 : ADD elasticsearch/scripts/initializeElasticSearch.sh /usr/local/bin/initializeElasticSearch
---> 8bd9e8821c4e
Step 3/5 : RUN chmod 755 /usr/local/bin/initializeElasticSearch
---> Running in 71184d2e0af6
Removing intermediate container 71184d2e0af6
---> bc015460473c
Step 4/5 : ADD elasticsearch/initial-data/cars.json /tmp/cars.json
---> b7140ea04924
Step 5/5 : ENTRYPOINT ["initializeElasticSearch"]
---> Running in f29015d87c1d
Removing intermediate container f29015d87c1d
---> 5faf42e80d33
Successfully built 5faf42e80d33
Successfully tagged docker_elasticsearch2:latest
WARNING: Image for service elasticsearch2 was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Starting elasticsearch ... done
Creating elasticsearch2 ... done
Attaching to elasticsearch, elasticsearch2
elasticsearch2 | /opt/jdk-11.0.1
elasticsearch2 | which: no java in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/share/elasticsearch/.local/bin:/usr/share/elasticsearch/bin)
elasticsearch2 | could not find java; set JAVA_HOME or ensure java is in PATH
elasticsearch | OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
elasticsearch2 |
elasticsearch2 | % Total % Received % Xferd Average Speed Time Time Time Current
elasticsearch2 | Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed connect to 0.0.0.0:9200; Connection refused

elasticsearch.yml
version: '2.0'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
container_name: elasticsearch
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- esnet
elasticsearch2:
build:
context: .
dockerfile: elasticsearch/elasticsearch-Migration.Dockerfile
container_name: elasticsearch2
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=elasticsearch"
- network.host=0.0.0.0
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata2:/usr/share/elasticsearch/data
networks:
- esnet

volumes:
esdata1:
driver: local
esdata2:
driver: local

networks:
esnet:

第二个 flex 搜索容器是使用上下文和带有docker文件的路径构建的(elasticsearch-Migration.Dockerfile)。所以这是我的 docker 文件
FROM docker.elastic.co/elasticsearch/elasticsearch:6.6.1

# script to orchestrate the automatic index creation.

ADD elasticsearch/scripts/initializeElasticSearch.sh /usr/local/bin/initializeElasticSearch
RUN chmod 755 /usr/local/bin/initializeElasticSearch

#
ADD elasticsearch/initial-data/cars.json /tmp/cars.json


ENTRYPOINT ["initializeElasticSearch"]

我的initializeElasticSearch.sh如下。
#!/usr/bin/env bash
export JAVA_HOME=/opt/jdk-11.0.1

echo $JAVA_HOME

su - elasticsearch -c 'bash /usr/share/elasticsearch/bin/elasticsearch'

sleep 5
echo
curl -XPOST http://0.0.0.0:9200/cars/car/_bulk --data-binary @/tmp/cars.json
sleep 5

任何想法我该如何解决找不到Java的问题

谢谢

最佳答案

您可以在export JAVA_HOME=/opt/jdk-11.0.1中执行initializeElasticSearch.sh,但是最终在执行elasticsearch时,您使用su -,这意味着您不再在导出JAVA_HOME的 shell 中运行elasticsearch

要修复它,您需要将JAVA_HOME添加到真正执行elasticsearch的 shell 中,如下所示:

su - elasticsearch -c 'bash -c "export JAVA_HOME=/opt/jdk-11.0.1; /usr/share/elasticsearch/bin/elasticsearch"'

关于docker - 无法启动 Elasticsearch ,因为找不到JAVA_HOME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57599614/

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