Running Elasticsearch and Kibana as Docker Containers
Setting Up a Single-Node Elasticsearch Container for Development with docker run.
To quickly set up Elasticsearch in a single-node development mode, you can run it as a container using the following command, with the option to easily integrate Kibana for data visualization.
# 1 Create network
docker network create elastic-net
#2 Set the environment variables
export ELASTIC_PASSWORD=$(openssl rand -base64 16)
export KIBANA_PASSWORD=$(openssl rand -base64 16)export ELASTIC_VERSION=8.15.0
#4 Run Elasticsearch
docker run -p 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:$ELASTIC_VERSION
# Check logs for "current.health":"GREEN"
docker logs elasticsearch | grep '"current.health":"GREEN"'#5 Verify Elasticsearch Health API
curl -u elastic:$ELASTIC_PASSWORD \
http://127.0.0.1:9200/_cluster/health\?wait_for_status\=yellow\&pretty#6 Set the kibana_system password in the Elasticsearch 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'#7 Run Kibana
docker run -p 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:$ELASTIC_VERSION#8 Copy $ELASTIC_PASSWORD Clipboard
# macOs
echo $ELASTIC_PASSWORD | pbcopy
# Windows using gitbash
echo $ELASTIC_PASSWORD | clip
#linux
echo $ELASTIC_PASSWORD | xclip -selection clipboard#9 Open the Kibana on the browser
user: elastic
password: Paste from Clipboard copied in 8th step
To check the logs of the container
docker ps -adocker logs elasticsearchFor more hacks on docker basic commands check with the following story
All my elastic stack stories are here
