gpt4 book ai didi

docker - 关于docker-compose up时docker容器的退出

转载 作者:行者123 更新时间:2023-12-02 19:18:08 24 4
gpt4 key购买 nike

我正在尝试将 Elasticsearch 与 docker 结合使用。

您可以在此处查看指南 -> https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

下面是我的 docker-compose.yml

version: '2.2'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
container_name: elasticsearch1
environment:
- node.name=master-node
- cluster.name=es-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- es-data01:/usr/share/elasticsearch/data
ports:
- 127.0.0.1:9200:9200
- 127.0.0.1:9300:9300
networks:
- elastic
stdin_open: true
tty: true

elasticsearch2:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
container_name: elasticsearch2
environment:
- node.name=data-node1
- cluster.name=es-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=elasticsearch1"
ports:
- 127.0.0.1:9301:9300
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- es-data02:/usr/share/elasticsearch/data
networks:
- elastic
stdin_open: true
tty: true

volumes:
es-data01:
driver: local
es-data02:
driver: local

networks:
elastic:
# driver: bridge

问题是

  1. I cannot connect by curl -XGET localhost:9200
  2. docker container exits automatically after few seconds

你能帮帮我吗?

ps:当我尝试 docker run 时,它起作用了。它们有什么区别?

docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch -it --rm -v els:/usr/share/elasticsearch/data -e "discovery.type=single-节点”docker.elastic.co/elasticsearch/elasticsearch:7.7.0

最佳答案

请使用docker logs <your stopped container-id>检查容器日志,在这里您可以使用 docker ps -a 获取容器 ID命令。

另请关注this SO answer和 s et the memory requirements这将帮助您在 docker 中运行 Elasticsearch。如果它没有帮助,请提供您可以获得的日志,如前所述。

根据评论添加更新的 docker-compose

version: '2.2'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
container_name: elasticsearch1
environment:
- node.name=master-node
- node.master=true
- cluster.name=es-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "cluster.initial_master_nodes=master-node"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- es-data01:/usr/share/elasticsearch/data
ports:
- 127.0.0.1:9200:9200
- 127.0.0.1:9300:9300
networks:
- elastic
stdin_open: true
tty: true

elasticsearch2:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
container_name: elasticsearch2
environment:
- node.name=data-node1
- node.master=false
- cluster.name=es-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "cluster.initial_master_nodes=master-node"
ports:
- 127.0.0.1:9301:9300
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- es-data02:/usr/share/elasticsearch/data
networks:
- elastic
stdin_open: true
tty: true

volumes:
es-data01:
driver: local
es-data02:
driver: local

networks:
elastic:
# driver: bridge

关于docker - 关于docker-compose up时docker容器的退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62037965/

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