# Add some default data to ES when docker first run

**URL:** <https://discuss.elastic.co/t/add-some-default-data-to-es-when-docker-first-run/338701>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [July 18, 2023, 4:27pm UTC](https://discuss.elastic.co/t/add-some-default-data-to-es-when-docker-first-run/338701 "2023-07-18T16:27:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TranTruongMMCII](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trantruongmmcii/32/123602_2.png) [@TranTruongMMCII](https://discuss.elastic.co/u/TranTruongMMCII)\
**Post date:** [July 18, 2023, 4:27pm UTC](https://discuss.elastic.co/t/add-some-default-data-to-es-when-docker-first-run/338701/1 "2023-07-18T16:27:24Z")

</div>

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

```auto
  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

```auto
ELASTIC_USERNAME=elastic # default `elastic`
ELASTIC_PASSWORD=trantruongmmcii
ELASTIC_PORT=9201
ELASTIC_X_PORT=9301
ELASTIC_VERSION=8.8.1

```

my dockerfile

```auto
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

```auto
#!/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

---

<div class="post-metadata">

**Author:** ![eMitch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emitch/32/93607_2.png) [@eMitch](https://discuss.elastic.co/u/eMitch)\
**Post date:** [July 18, 2023, 4:36pm UTC](https://discuss.elastic.co/t/add-some-default-data-to-es-when-docker-first-run/338701/2 "2023-07-18T16:36:57Z")

</div>

Hi @TranTruongMMCII and welcome to the community!

What errors are you receiving when you try to add your data this way?

By default, Elastic \> 8.0 is coming with security enabled, plus you're using `- xpack.security.enabled=true` which changes the base security as well.

Since your CURL commands are not https with a cert or credentials, I would expect them to fail.

I wrote a small blog about getting started with Elastic Stack on Docker which also gives the ability to add data via Filbeat and/or Logstash. Take a look and see if it helps at all: [Getting started with the Elastic Stack and Docker-Compose | Elastic Blog](https://www.elastic.co/blog/getting-started-with-the-elastic-stack-and-docker-compose)

---

<div class="post-metadata">

**Author:** ![TranTruongMMCII](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trantruongmmcii/32/123602_2.png) [@TranTruongMMCII](https://discuss.elastic.co/u/TranTruongMMCII)\
**Post date:** [July 19, 2023, 2:30am UTC](https://discuss.elastic.co/t/add-some-default-data-to-es-when-docker-first-run/338701/3 "2023-07-19T02:30:28Z")

</div>

Thank you sir, I will read you blog now.  
The error I got `curl: (7) Failed to connect to localhost port 9201: Connection refused`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 16, 2023, 2:31am UTC](https://discuss.elastic.co/t/add-some-default-data-to-es-when-docker-first-run/338701/4 "2023-08-16T02:31:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
