15

How can I configure elasticsearch docker containers (elasticsearch:7.5.0) to use fewer resources and run in a nonproduction mode?

I want to run containers in Jenkins and on my desktop and am hitting the requirement from this elastic doc for running docker images in production

I'd like to figure out how I can modify my elasticsearch.yml which I copy into the container to configure it to set the container into a less resource-intensive mode.

anyone know how to do this?

4
  • I haven't yet. I should be able to circle back to test in a few days. Thanks for the info Commented Feb 27, 2020 at 18:18
  • 1
    Not only does that work, but it is also how our test lab environment scripts do it... and I wrote the orchestration of those and missed it. This context is for our build machine and desktop testing. Thanks Commented Feb 27, 2020 at 20:20
  • 1
    You're welcome. Let's hope it helps the next person too Commented Feb 28, 2020 at 14:28
  • Thanks for the kind words :) Commented Feb 28, 2020 at 14:57

3 Answers 3

24

You can run your docker in development mode and create a single node ES cluster by following official ES link on single node ES cluster. As mention in this link.

To start a single-node Elasticsearch cluster for development or testing, specify single-node discovery to bypass the bootstrap checks:

In-short all you need to do is add -e "discovery.type=single-node" in your docker command, which would enable the dev mode and then you don't have to satisfy the hard limits of production environments ie it bypass bootstrap checks.

More information on your settings and how to turn it off can be found here

node.store.allow_mmap. This is a boolean setting indicating whether or not memory-mapping is allowed. The default is to allow it.

So, if -e "discovery.type=single-node env. doesn't turn it off, then you can explicitly set it false in your elasticsearch.yml.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm using elasticsearch 8.7.0 and spinning-up a container in a Jenkins pipeline, and I needed to set both discovery.type=single-node and node.store.allow_mmap=false.
11

If you're reading this trying to find out how to do it when using docker-compose:

With an environment key

docker-compose.yml:

  elasticsearch:
    environment:
      - discovery.type=single-node

With a custom elasticsearch.yml

Create elasticsearch.yml:

discovery:
  type: single-node

Mount it as a volume on your container in docker-compose.yml:

  elasticsearch:
    volumes:
      - /path-to/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro

Make sure the first part actually a path, it has to start with / or ./ or else it's going to treat it as a named volume. The second part is the path inside the container so it can be left as is.

The file must be in a location you've enabled File Sharing for in your Docker application. Set this up in Preferences > Resources > File Sharing if you haven't.

Comments

1

I have also faced this issue when I was using this docker.elastic.co/elasticsearch/elasticsearch:7.6.2 elastic-search docker image for a single node cluster.

The error I was getting is:

ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

To start a single-node Elasticsearch cluster with Docker

Solution1

So the solution would be to run a docker image with an environment variable -e "discovery.type=single-node" in docker run command.

docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.6.2

Solution2

Add this "discovery.seed_hosts : 127.0.0.1:9300" in eleasticsearch.yml file. And build your own docker image and use it.

Dockerfile will look like this.

FROM docker.elastic.co/elasticsearch/elasticsearch:7.6.2
RUN echo discovery.seed_hosts : 127.0.0.1:9300 >> /usr/share/elasticsearch/config/elasticsearch.yml 
RUN cat /usr/share/elasticsearch/config/elasticsearch.yml

For more details click here.

3 Comments

I already provided the solution 1 in my answer and about the solution 2, I am not sure how it works, can you explain why it avoid the production checks and run it in dev mode ?
@OpsterElasticsearchNinja Just now I have updated the answer and provided the Dockerfile so please have a look. Here we are using loopback address as seed_hosts so elastic search will then only be accessible from the host machine itself. I hope this is more clear now.
why to make it complex?, simply using discovery.type=single-node skips the production checks and mentioned in elasticsearch config and has a lot of documentation around it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.