# How to create Elasticsearch docker container, create indexes and seed data in one step?

**URL:** <https://discuss.elastic.co/t/how-to-create-elasticsearch-docker-container-create-indexes-and-seed-data-in-one-step/167561>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [February 8, 2019, 1:55am UTC](https://discuss.elastic.co/t/how-to-create-elasticsearch-docker-container-create-indexes-and-seed-data-in-one-step/167561 "2019-02-08T01:55:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpm1984](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpm1984/32/36595_2.png) [@rpm1984](https://discuss.elastic.co/u/rpm1984)\
**Post date:** [February 8, 2019, 1:55am UTC](https://discuss.elastic.co/t/how-to-create-elasticsearch-docker-container-create-indexes-and-seed-data-in-one-step/167561/1 "2019-02-08T01:55:02Z")

</div>

Hi there!

So i'm using the Elasticsearch docker image to develop locally. Works great.

Now what i'd like to do as part of a `docker-compose` script is to:

- Create an instance of Elasticsearch via docker image
- Create index
- Import data using Bulk API (e.g a JSON file in the source control repository)

Initially i was thinking i could have a Dockerfile that started from the Elasticsearch base image, then somehow used curl commands to index/add data, but the issue is the container isn't 'up' yet.

The ideal situation is i'd like to run a command like this:

```auto
docker-compose up my-elastic-search-db

```

Then everything is up and ready to go.

How do people solve this? I've seen a few posts that a few years old of people running scripts 'waiting' for it to be up.. so just seeing if this is still the way, or have Elastic made it easier.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 8, 2019, 3:17am UTC](https://discuss.elastic.co/t/how-to-create-elasticsearch-docker-container-create-indexes-and-seed-data-in-one-step/167561/2 "2019-02-08T03:17:27Z")

</div>

May be have a look at the healthcheck part of this example:

> <https://github.com/elastic/stack-docker/blob/master/docker-compose.yml>

---

<div class="post-metadata">

**Author:** ![rpm1984](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpm1984/32/36595_2.png) [@rpm1984](https://discuss.elastic.co/u/rpm1984)\
**Post date:** [February 8, 2019, 5:07am UTC](https://discuss.elastic.co/t/how-to-create-elasticsearch-docker-container-create-indexes-and-seed-data-in-one-step/167561/3 "2019-02-08T05:07:59Z")

</div>

Hi @dadoonet, thanks for the answer.

Can you please elaborate on how healthcheck can help?

When and where would my 'curl' occur to insert the data? It can't be in the custom Dockerfile for the elasticsearch image right? It would need to be _after_ the healthcheck..

So.. would i just have another 'service' in docker compose that `depends_on` the elasticsearch image, and this 'service' is actually just a script that uses curl to insert the data?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 8, 2019, 10:39am UTC](https://discuss.elastic.co/t/how-to-create-elasticsearch-docker-container-create-indexes-and-seed-data-in-one-step/167561/4 "2019-02-08T10:39:25Z")

</div>

> [@rpm1984](#):
>
> So.. would i just have another 'service' in docker compose that `depends_on` the elasticsearch image, and this 'service' is actually just a script that uses curl to insert the data?

Yes. That's my feeling too.

---

<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:** [March 8, 2019, 10:39am UTC](https://discuss.elastic.co/t/how-to-create-elasticsearch-docker-container-create-indexes-and-seed-data-in-one-step/167561/5 "2019-03-08T10:39:30Z")

</div>

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