Docker Swarm is a clustering and orchestration tool for Docker containers. Elasticsearch is a distributed, open-source search and analytics engine.
To run Elasticsearch on Docker Swarm, you can use the official Elasticsearch Docker image from Docker Hub. Here are the steps:
- Create a Docker Swarm cluster with at least two nodes.
- Create an overlay network for the Elasticsearch cluster:
docker network create --driver overlay elastic
- Deploy Elasticsearch to the Swarm using the following command:
In this example, we’re deploying three Elasticsearch instances (replicas) on the Swarm, all running on manager nodes (constraint).docker service create \ --name elasticsearch \ --network elastic \ --constraint 'node.role == manager' \ --replicas 3 \ elasticsearch:7.9.3
- Verify that the Elasticsearch instances are running and healthy:
docker service ls docker service ps elasticsearch
- Connect to Elasticsearch using its REST API, which should be available on port 9200 of any of the Swarm nodes.
That’s it! You now have a highly available Elasticsearch cluster running on Docker Swarm.