Last active
April 5, 2025 22:18
-
-
Save IdrisAkintobi/d8001cc6bf3d35f6794a9591c73fcc21 to your computer and use it in GitHub Desktop.
Elasticsearch-Docker
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
# Use the official Elasticsearch image from Docker Hub | |
FROM docker.elastic.co/elasticsearch/elasticsearch:8.17.2 | |
# Copy the custom elasticsearch.yml into the container | |
COPY ./elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml | |
# Expose Elasticsearch port | |
EXPOSE 9200 | |
# Run Elasticsearch | |
CMD ["eswrapper"] |
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
# Elasticsearch Configuration | |
cluster.name: "my-cluster" | |
node.name: "node-1" | |
path.data: /usr/share/elasticsearch/data | |
path.logs: /usr/share/elasticsearch/logs | |
# Network settings | |
network.host: 0.0.0.0 | |
http.port: 9200 | |
transport.port: 9300 # Use transport.port instead of transport.tcp.port | |
# Discovery settings for single-node setup | |
discovery.type: single-node | |
# Security settings (corrected) | |
xpack.security.enabled: true | |
xpack.security.authc.api_key.enabled: true # Corrected setting | |
# Optional heap size settings (you can modify based on your machine's capabilities) | |
bootstrap.memory_lock: true | |
indices.fielddata.cache.size: 30% |
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
# Variables | |
IMAGE_NAME = elasticsearch | |
CONTAINER_NAME = elasticsearch-container | |
PORT = 9200 | |
VOLUME_NAME = elasticsearch-data | |
CONFIG_FILE = elasticsearch.yml | |
JAVA_OPTS = '-Xms512m -Xmx512m' | |
# Default password is elastic | |
ELASTIC_PASSWORD ?= elastic | |
# Prompt for the password if not provided | |
run: | |
@echo "Enter Elasticsearch password (default: $(ELASTIC_PASSWORD)):" | |
@read -p "Password: " input_password; \ | |
if [ -z "$$input_password" ]; then \ | |
input_password=$(ELASTIC_PASSWORD); \ | |
fi; \ | |
docker run -d \ | |
--name $(CONTAINER_NAME) \ | |
-p $(PORT):9200 \ | |
-v $(VOLUME_NAME):/usr/share/elasticsearch/data \ | |
-v $(PWD)/$(CONFIG_FILE):/usr/share/elasticsearch/config/elasticsearch.yml \ | |
-e ELASTIC_PASSWORD=$$input_password \ | |
-e ES_JAVA_OPTS=$(JAVA_OPTS) \ | |
$(IMAGE_NAME) | |
# Build the Docker image | |
build: | |
docker build -t $(IMAGE_NAME) . | |
# Start the Elasticsearch container | |
start: | |
docker start $(CONTAINER_NAME) | |
# Stop the Elasticsearch container | |
stop: | |
docker stop $(CONTAINER_NAME) | |
# Remove the Elasticsearch container and associated volume | |
clean: | |
docker rm -f $(CONTAINER_NAME) | |
docker volume rm $(VOLUME_NAME) | |
# Show logs from the Elasticsearch container | |
logs: | |
docker logs $(CONTAINER_NAME) | |
# List all Docker containers | |
ps: | |
docker ps -a | |
# Show status of Elasticsearch container | |
status: | |
docker inspect -f '{{.State.Status}}' $(CONTAINER_NAME) | |
# Help command to display available targets | |
help: | |
@echo "Available targets:" | |
@echo " build - Build the Docker image" | |
@echo " run - Run the Elasticsearch container" | |
@echo " start - Start the Elasticsearch container" | |
@echo " stop - Stop the Elasticsearch container" | |
@echo " clean - Remove the Elasticsearch container and associated volume" | |
@echo " logs - Show logs from the Elasticsearch container" | |
@echo " ps - List all Docker containers" | |
@echo " status - Show the status of the Elasticsearch container" | |
@echo " help - Display this help message" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment