Setup and configure Elasticsearch on local machine with Docker

instructions how to configure your ES in Docker

As written on the official page about how to Install Elasticsearch with Docker you need:

  1. Install Docker (of course)
  2. Create a new docker network
    docker network create elastic
    
  3. Start Elasticsearch in Docker. A password is generated each time for a new cluster. If you don't see it because of a bunch of logs, scroll down and it will be there, together with a Kibana enrolment token.

     docker run --name es01 --net elastic -p 9200:9200 -p 9300:9300 -it docker.elastic.co/elasticsearch/elasticsearch:8.4.2
    

If you run it with this command, ES will have default configurations. If you want to override them you need to mount a configuration file instead of one inside the container. I advise you to copy one from this running container. Then stop it, and delete it from docker. And launch another one with a mounted file.

To do it, do the following: Copy conf file from container to your host

docker cp es01:/usr/share/elasticsearch/config/elasticsearch.yml .

Then change any configuration you like. For example, you can turn off authentification at all:

xpack.security.enabled: false

xpack.security.enrollment.enabled: false

And comment/uncomment anything you want.

Then launch a new container with mounted conf file

docker run --name es01 \
        --net elastic \
        -p 9200:9200 -p 9300:9300 \
        -v "$(pwd)"/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
        -e "discovery.type=single-node" -t docker.elastic.co/elasticsearch/elasticsearch:8.4.2

Be aware to set the full path to your local conf file. Otherwise, it will not work.