Last active
March 28, 2021 09:27
-
-
Save AlessandroVaccarino/714c410bcc1890979706b813efa3090f to your computer and use it in GitHub Desktop.
A simple shell to run ElasticSearch and Kibana docker images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #Some variables | |
| ELASTICSEARCH_VERSION="6.5.3" | |
| KIBANA_VERSION="6.5.3" | |
| ELASTICSEARCH_PWD="secret" | |
| #Define a "wait for service" function | |
| WaitForService () { | |
| while (true); | |
| do | |
| if curl -s --head $1 | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null; | |
| then | |
| printf "$3\n" | |
| break | |
| else | |
| printf "$2\n" | |
| sleep 2s | |
| fi | |
| done | |
| } | |
| #Create a common network, to let the 2 containers communicate | |
| docker network create elastic_network --driver=bridge | |
| #Create ElasticSearch | |
| docker run \ | |
| -d \ | |
| --restart always \ | |
| -p 9200:9200 \ | |
| -p 9300:9300 \ | |
| --network elastic_network \ | |
| -e "discovery.type=single-node" \ | |
| -e "transport.host=0.0.0.0" \ | |
| -e ELASTIC_PASSWORD=$ELASTICSEARCH_PWD \ | |
| -e "bootstrap.memory_lock=true" \ | |
| --ulimit memlock=-1:-1 \ | |
| --name elastic \ | |
| docker.elastic.co/elasticsearch/elasticsearch:$ELASTICSEARCH_VERSION | |
| #Wait for ElasticSearch to be started | |
| WaitForService 'http://localhost:9200' 'Waiting for ElasticSearch to be started...' 'ElasticSearch started!' | |
| #Change allocated memory | |
| sudo docker exec -it elastic sh -c "sed -i 's/-Xms1g/-Xms8g/g' /usr/share/elasticsearch/config/jvm.options" | |
| sudo docker exec -it elastic sh -c "sed -i 's/-Xmx1g/-Xmx24g/g' /usr/share/elasticsearch/config/jvm.options" | |
| #Restart ElasticSearch to make change available | |
| docker restart elastic | |
| #Wait for ElasticSearch to be started | |
| WaitForService 'http://localhost:9200' 'Waiting for ElasticSearch to be started...' 'ElasticSearch started!' | |
| #Start Kibana | |
| docker run \ | |
| -d \ | |
| --restart always \ | |
| --network elastic_network \ | |
| -e "ELASTICSEARCH_URL=http://elastic:9200" \ | |
| -e ELASTICSEARCH_PASSWORD="$ELASTICSEARCH_PWD" \ | |
| -p 5601:5601 \ | |
| --name kibana \ | |
| docker.elastic.co/kibana/kibana:$KIBANA_VERSION | |
| #Wait for Kibana to be started | |
| WaitForService 'http://localhost:5601' 'Waiting for Kibana to be started...' 'Kibana started!' | |
| #Bye bye | |
| printf "All services are up. Have fun!\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment