Nethence Newdoc Olddoc Lab Your IP BBDock  

Setting up an ElasticSearch container

Introduction

Fetch / Update the official image

Fetch/update the Elastic Search image and check, CAREFUL about the version needed for the application e.g. ES v2.x.x,

docker pull elasticsearch:2
docker images

Launch the container

Make sure the data folder doesn’t exist yet otherwise the init part that follows doesn’t make sense,

ls -ld /data/elasticprod/
#sudo rm -rf /data/elasticprod/

Make sure the 9200 & 9300 ports are available on the docker host if you want to expose them,

    netstat -antpe --inet --inet6 | grep LISTEN | egrep '9200|9300'

Launch the docker instance for ES and map the data volume to /data/elasticprod/,

app=elasticprod
volume=/data/$app
docker ps -a | grep $app
#docker run -d --name $app -h $app -v $volume:/usr/share/elasticsearch/data elasticsearch:2 -p 9200:9200 -p 9300:9300
docker run -d --name $app -h $app -v $volume:/usr/share/elasticsearch/data elasticsearch:2
docker ps -a | grep $app
docker logs $app

If you need to further tweak the thing,

    docker exec -ti $app bash

Ready to go

Check that you can access the service from another container,

docker run -ti --link elasticprod:elastic ubuntu
apt -y update && apt -y install netcat
ping -c1 elastic
nc -z -v elastic 9200 9300

You can now inject the indexes to be used for the application(s).

Now check that you can see the indexes from that other container,

apt -y update && apt -y install curl
curl 'elastic:9200/_cat/indices?v'
curl -XGET 'http://elastic:9200/_cluster/health?pretty=true'

Note. the indices command just lists the indexes, it doesn’t actually check if there is something in it. Note. the health command shows you the cluster status, should be yellow since we only have one ES node right now.

Operations / Maintenance

Same command as for launching it the first time, see the docker run command above.

See Operating Docker Containers for common operations.

References


Home | GitHub | Donate | Contact