To create a Docker Compose file for Elasticsearch with a persistent volume, you can use the volumes
and volume_driver
options in the elasticsearch
service configuration. Here is an example docker-compose.yml
file:
version: '3.7'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.1
volumes:
- data:/usr/share/elasticsearch/data
environment:
- node.name=elasticsearch
- cluster.name=elasticsearch
- discovery.seed_hosts=elasticsearch
- cluster.initial_master_nodes=elasticsearch
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
ports:
- 9200:9200
networks:
- elasticsearch
volumes:
data:
driver: local
driver_opts:
o: bind
type: none
device: /path/to/data/directory
networks:
elasticsearch:
This docker-compose.yml
file will create a Docker container for Elasticsearch, and mount a persistent volume at the path /path/to/data/directory
on the host machine. This volume will be used to store the data for Elasticsearch.
To use this docker-compose.yml
file, save it to a file on your local machine, and run the following command from the directory where the file is saved:
docker-compose up -d
docker-compose ps
This will start the Elasticsearch container and mount the persistent volume.
I hope this helps! Let me know if you have any other questions.