Certainly! Below is a comprehensive docker-compose.yml file tailored to your requests. This example includes Elasticsearch and Kibana, adhering to Alpine image preferences, health checks, static IP assignments, and some additional configurations like resource limits and logging.
version: '3.8'
services:
elasticsearch:
# Use Alpine-based Elasticsearch image if available; otherwise, the latest version
image: elasticsearch:8.8.1-alpine
container_name: elasticsearch_container
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:9200/_cluster/health || exit 1"]
interval: 30s
timeout: 10s
retries: 5
environment:
- discovery.type=single-node
- ES_JAVA_OPTS=-Xms512m -Xmx512m # Set heap size for Elasticsearch
- ELASTIC_PASSWORD=your_secure_password # Set Elasticsearch password
volumes:
- es_data:/usr/share/elasticsearch/data # Data persistence
networks:
my_network:
ipv4_address: 192.168.100.10 # Static IP for Elasticsearch
deploy:
resources:
limits:
cpus: '1.0'
memory: 1Gi # Set memory limit
restart: always # Restart policy for failed containers
logging:
driver: json-file # Use json-file logging driver
options:
max-size: "10m" # Max size for log files
max-file: "3" # Max number of log files to keep
kibana:
# Use Alpine-based Kibana image if available; otherwise, the latest version
image: kibana:8.8.1-alpine
container_name: kibana_container
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:5601/api/status || exit 1"]
interval: 30s
timeout: 10s
retries: 5
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200 # Address of the Elasticsearch service
- ELASTICSEARCH_USERNAME=elastic
- ELASTICSEARCH_PASSWORD=your_secure_password # Use the same password as above
ports:
- "5601:5601" # Expose Kibana UI port
networks:
my_network:
ipv4_address: 192.168.100.20 # Static IP for Kibana
depends_on:
elasticsearch: # Ensure Elasticsearch is started before Kibana
condition: service_healthy
deploy:
resources:
limits:
cpus: '0.5'
memory: 512Mi # Set memory limit
restart: always # Restart policy for failed containers
logging:
driver: json-file # Use json-file logging driver
options:
max-size: "10m" # Max size for log files
max-file: "3" # Max number of log files to keep
networks:
my_network:
driver: bridge # Use bridge network
ipam:
config:
- subnet: 192.168.100.0/24 # Custom subnet for static IP assignment
volumes:
es_data: # Named volume for Elasticsearch data persistence
Explanation of Key Components:
- Image Selection: The configuration checks for an Alpine version of Elasticsearch and Kibana. You should verify the available versions and replace
8.8.1-alpine with the latest version if needed.
- Health Checks: The health checks ensure that Elasticsearch and Kibana are running correctly before they're deemed healthy. They attempt to hit specific HTTP endpoints.
- Environment Variables: Use relevant environment variables for essential configurations such as passwords, Elasticsearch hosts, and memory options.
- Volumes: The Elasticsearch service persists its data in a named volume (
es_data), ensuring data retention across container restarts.
- Networking: A custom bridge network (
my_network) is defined, with static IP addresses assigned to each service.
- Resource Limits: Resource limits for memory and CPU cores help manage the service loads more efficiently.
- Restart Policy: The
restart: always configuration allows services to restart automatically in case of failure.
- Logging Configuration: Logs are stored using the
json-file driver with controlled size and file retention to help in debugging issues.
You can customize the password, memory allocation, and specific versions based on your setup needs. Make sure to replace any passwords with secure values.