Skip to content

Instantly share code, notes, and snippets.

@qzchenwl
Created April 27, 2024 07:04
Show Gist options
  • Save qzchenwl/edfa6ebaa4e8fbf3635a275bd0a7f231 to your computer and use it in GitHub Desktop.
Save qzchenwl/edfa6ebaa4e8fbf3635a275bd0a7f231 to your computer and use it in GitHub Desktop.
elasticsearch docker compose
services:
setup:
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0
user: "0"
command: >
bash -c '
if [ x${ELASTIC_PASSWORD} == x ]; then
echo "Set the ELASTIC_PASSWORD environment variable in the .env file";
exit 1;
elif [ x${KIBANA_PASSWORD} == x ]; then
echo "Set the KIBANA_PASSWORD environment variable in the .env file";
exit 1;
fi;
echo "Waiting for Elasticsearch availability";
until curl -s http://elasticsearch:9200 | grep -q "missing authentication credentials"; do sleep 30; done;
echo "Setting kibana_system password";
until curl -s -X POST -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" http://elasticsearch:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done;
touch /tmp/setup-completed
echo "All done!"
tail -f /dev/null
'
healthcheck:
test: [ "CMD-SHELL", "test -f /tmp/setup-completed" ]
interval: 10s
timeout: 10s
retries: 120
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0
container_name: elasticsearch
environment:
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=false
- xpack.security.transport.ssl.enabled=false
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- discovery.type=single-node
ulimits:
nofile:
soft: 65536
hard: 65536
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
ports:
- "9200:9200"
- "9300:9300"
healthcheck:
test:
[ "CMD-SHELL", "curl -s http://localhost:9200 | grep -q 'missing authentication credentials'" ]
interval: 10s
timeout: 10s
retries: 120
kibana:
depends_on:
elasticsearch:
condition: service_healthy
setup:
condition: service_healthy
image: docker.elastic.co/kibana/kibana:8.13.0
container_name: kibana
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
- ELASTICSEARCH_USERNAME=kibana_system
- ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
ports:
- "5601:5601"
volumes:
elasticsearch-data:
driver: local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment