在docker-compose中,对Elasticsearch的健康检查会导致任何依赖的服务停止,因为容器始终处于不健康状态。当我运行
我正在尝试启动 Metricbeat,使 Elasticsearch、Kibana 和 Logstash 一起启动:
docker ps -a --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
命令时,可以看到这种情况。NAMES IMAGE STATUS
elasticsearch elasticsearch:7.12.1 Up 26 seconds (unhealthy)
我正在尝试启动 Metricbeat,使 Elasticsearch、Kibana 和 Logstash 一起启动:
metricbeat:
image: elastic/metricbeat:7.12.1
user: root
depends_on:
elasticsearch:
condition: service_healthy
kibana:
condition: service_healthy
logstash:
condition: service_healthy
redis:
condition: service_healthy
我该如何确保elasticsearch(以及其他容器)处于健康状态,并允许metricbeat在所有可用资源的基础上启动?
除非绝对必要,否则我会避免为它们创建Docker镜像。
我的docker-compose配置如下:
version: '3.7'
services:
elasticsearch:
# specifying discovery.type='single-node' bypasses bootstrapping checks.
image: elasticsearch:7.12.1
container_name: elasticsearch
healthcheck:
test: [ "CMD", "curl", "--fail" , "http://elasticsearch:9200/_cluster/health?wait_for_status=green&timeout=1s", "||", "exit", "1" ]
interval: 5s
timeout: 3s
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
networks:
- elastic
ports:
- 9200:9200
- 9300:9300
labels:
co.elastic.metrics/module: "elasticsearch"
co.elastic.metrics/hosts: "http://elasticsearch:9200"
co.elastic.metrics/metricsets: "node_stats,node"
co.elastic.metrics/xpack.enabled: "true"
environment:
- node.name=elasticsearch
- cluster.name=cluster-7
- discovery.type=single-node
- 'ES_JAVA_OPTS=-Xms512m -Xmx512m'
- xpack.monitoring.enabled=true
- xpack.monitoring.elasticsearch.collection.enabled=true
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
cap_add:
- IPC_LOCK