Dear all,
I am new to ES. Now I want to create a docker to run ES, but I faced some errors. Firstly, I can create a docker to run ES and can interact with it. But I want to add some default data to index when docker first run, like "hello world". I tried many times but still get error. Can u help me?
My docker-compose.yml file
elasticsearch:
container_name: elasticsearch-container
image: elasticsearch-image
restart: always
build:
context: ./ElasticSearch
dockerfile: Dockerfile
args:
- ELASTIC_VERSION=${ELASTIC_VERSION}
environment:
- discovery.type=single-node
- xpack.security.enabled=true
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
ports:
- ${ELASTIC_PORT}:9200
- ${ELASTIC_X_PORT}:9300
volumes:
- elasticsearch_data:/db/data
env_file:
- .env
my .env file
ELASTIC_USERNAME=elastic # default `elastic`
ELASTIC_PASSWORD=trantruongmmcii
ELASTIC_PORT=9201
ELASTIC_X_PORT=9301
ELASTIC_VERSION=8.8.1
my dockerfile
ARG ELASTIC_VERSION
FROM docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION}
USER root
COPY insert_data.sh /usr/share/elasticsearch/
RUN chmod +x /usr/share/elasticsearch/insert_data.sh
RUN sed -i -e 's/\r$//' /usr/share/elasticsearch/insert_data.sh
CMD ["/bin/bash", "-c", "/usr/share/elasticsearch/insert_data.sh"]
EXPOSE 9200
my insert_data.sh
#!/bin/sh
while true; do
curl -sS -X GET -u ${ELASTIC_USERNAME}:${ELASTIC_PASSWORD} "http://localhost:9200/_cluster/health" | grep -q '"status":"green"'
if [ $? -eq 0 ]; then
break
fi
sleep 1
done
curl -X POST -u ${ELASTIC_USERNAME}:${ELASTIC_PASSWORD} "http://localhost:9200/my_index/_doc" -H 'Content-Type: application/json' -d '{"field": "value"}'
can you help me to edit to add some data when first run the docker, please