Run Elasticsearch locally in Docker (without security)
editRun Elasticsearch locally in Docker (without security)
editDO NOT USE THESE INSTRUCTIONS FOR PRODUCTION DEPLOYMENTS
The instructions on this page are for local development only. Do not use these instructions for production deployments, because they are not secure. While this approach is convenient for experimenting and learning, you should never run the service in this way in a production environment.
The following commands help you very quickly spin up a single-node Elasticsearch cluster, together with Kibana in Docker. Note that if you don’t need the Kibana UI, you can skip those instructions.
When would I use this setup?
editUse this setup if you want to quickly spin up Elasticsearch (and Kibana) for local development or testing.
For example you might:
- Want to run a quick test to see how a feature works.
- Follow a tutorial or guide that requires an Elasticsearch cluster, like our quick start guide.
- Experiment with the Elasticsearch APIs using different tools, like the Dev Tools Console, cURL, or an Elastic programming language client.
- Quickly spin up an Elasticsearch cluster to test an executable Python notebook locally.
Prerequisites
editIf you don’t have Docker installed, download and install Docker Desktop for your operating system.
Set environment variables
editConfigure the following environment variables.
export ELASTIC_PASSWORD="<ES_PASSWORD>" # password for "elastic" username export KIBANA_PASSWORD="<KIB_PASSWORD>" # Used _internally_ by Kibana, must be at least 6 characters long
Create a Docker network
editTo run both Elasticsearch and Kibana, you’ll need to create a Docker network:
docker network create elastic-net
Run Elasticsearch
editStart the Elasticsearch container with the following command:
docker run -p 127.0.0.1:9200:9200 -d --name elasticsearch --network elastic-net \ -e ELASTIC_PASSWORD=$ELASTIC_PASSWORD \ -e "discovery.type=single-node" \ -e "xpack.security.http.ssl.enabled=false" \ -e "xpack.license.self_generated.type=trial" \ docker.elastic.co/elasticsearch/elasticsearch:8.14.3
Run Kibana (optional)
editTo run Kibana, you must first set the kibana_system
password in the Elasticsearch container.
# configure the Kibana password in the ES container curl -u elastic:$ELASTIC_PASSWORD \ -X POST \ http://localhost:9200/_security/user/kibana_system/_password \ -d '{"password":"'"$KIBANA_PASSWORD"'"}' \ -H 'Content-Type: application/json'
Start the Kibana container with the following command:
docker run -p 127.0.0.1:5601:5601 -d --name kibana --network elastic-net \ -e ELASTICSEARCH_URL=http://elasticsearch:9200 \ -e ELASTICSEARCH_HOSTS=http://elasticsearch:9200 \ -e ELASTICSEARCH_USERNAME=kibana_system \ -e ELASTICSEARCH_PASSWORD=$KIBANA_PASSWORD \ -e "xpack.security.enabled=false" \ -e "xpack.license.self_generated.type=trial" \ docker.elastic.co/kibana/kibana:8.14.3
The service is started with a trial license. The trial license enables all features of Elasticsearch for a trial period of 30 days. After the trial period expires, the license is downgraded to a basic license, which is free forever. If you prefer to skip the trial and use the basic license, set the value of the xpack.license.self_generated.type
variable to basic instead. For a detailed feature comparison between the different licenses, refer to our subscriptions page.
Connecting to Elasticsearch with language clients
editTo connect to the Elasticsearch cluster from a language client, you can use basic authentication with the elastic
username and the password you set in the environment variable.
Expand for details
You’ll use the following connection details:
-
Elasticsearch endpoint:
http://localhost:9200
-
Username:
elastic
-
Password:
$ELASTIC_PASSWORD
(Value you set in the environment variable)
For example, to connect with the Python elasticsearch
client:
import os from elasticsearch import Elasticsearch username = 'elastic' password = os.getenv('ELASTIC_PASSWORD') # Value you set in the environment variable client = Elasticsearch( "http://localhost:9200", basic_auth=(username, password) ) print(client.info())
Here’s an example curl command using basic authentication:
curl -u elastic:$ELASTIC_PASSWORD \ -X PUT \ http://localhost:9200/my-new-index \ -H 'Content-Type: application/json'
Next steps
editUse our quick start guide to learn the basics of Elasticsearch: how to add data and query it.
Moving to production
editThis setup is not suitable for production use. For production deployments, we recommend using our managed service on Elastic Cloud. Sign up for a free trial (no credit card required).
Otherwise, refer to Install Elasticsearch to learn about the various options for installing Elasticsearch in a self-managed production environment, including using Docker.