Set up mapping in Elasticsearch during Docker run
I ended up doing this
docker-composer.yml
version: '2'services: elasticsearch: image: elasticsearch:2.3 command: elasticsearch -Des.network.host=0.0.0.0 ports: - "9200:9200" - "9300:9300" elasticsearch-mapping-init: build: elasticsearch-mapping-init links: - elasticsearch depends_on: - elasticsearch
and here is my elasticsearch-mapping-init/Dockerfile:
FROM ubuntu# Install packagesRUN apt-get update && \apt-get install -y curlCOPY docker-entrypoint.sh /ENTRYPOINT ["/docker-entrypoint.sh"]
and here is my elasticsearch-mapping-init/docker-entrypoint.sh
#!/bin/bashfor i in {30..0}; do if curl elasticsearch:9200; then curl -XPUT elasticsearch:9200/_template/log -d ' { "template" : "log-*", "settings": { "number_of_shards": 1 }, "mappings" : { } }'; break; fi sleep 2done
I believe this is not perfect, and I'm still looking for a better solution.