On all Hosts:
sudo sysctl -w vm.max_map_count=262144
On Host 1:
1. We initialize a docker swarm. Add `–advertise-addr X.X.X.X` if inside a private network
# docker swarm init
1. We create a network on docker
# docker network create --driver overlay --subnet 10.0.10.0/24 --opt encrypted elastics
“Overlay networks connect multiple Docker daemons together and enable swarm services to communicate with each other.” [2]
2. We initialize the docker containers with 3 copies
docker service create --name elasticsearch --network=elastics \ --replicas 3 \ --env SERVICE_NAME=elasticsearch \ --env "ES_JAVA_OPTS=-Xms256m -Xmx256m -XX:-AssumeMP" \ --publish 9200:9200 \ --publish 9300:9300 \ youngbe/docker-swarm-elasticsearch:5.5.0
3. We get the command to generate the joining link
# docker swarm join-token worker To add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-TOKEN \ X.X.X.X:2377
On Worker Host
1. Type the command from the last step from host 1
# docker swarm join \ --token TOKEN \ X.X.X.X:2377
On Master 1
1. We now setup nginx
docker service create --name meranginx --network=elastics nginx
docker service create --name nginx --network=elastics --mount type=bind,source=/root/meradockernginx/elasticsearch.conf,destination=/etc/nginx/conf.d/elasticsearch.conf nginx
To be continued…
#TODO: make a conf file for nginx which listens on port 9200 and uses `elasticsearch` as backend server
References:
[1] https://github.com/imyoungyang/docker-swarm-elasticsearch
[2] https://docs.docker.com/network/#network-drivers