Skip to content

Instantly share code, notes, and snippets.

@shavo007
Created June 8, 2017 05:19
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save shavo007/d426d9838c4dcadfbcd384ac68b6c69d to your computer and use it in GitHub Desktop.
Save shavo007/d426d9838c4dcadfbcd384ac68b6c69d to your computer and use it in GitHub Desktop.
Docker compose (mysql, elasticsearch, kibana) with healthchecks
version: '2.1'
services:
mysql:
container_name: mysql
image: mysql:5.7
ports:
- "13306:3306"
environment:
- MYSQL_ROOT_PASSWORD=Welcome123
healthcheck:
test: ["CMD-SHELL", "mysqladmin -h 'localhost' -u root -pWelcome123 ping --silent"]
interval: 30s
timeout: 30s
retries: 3
volumes:
- mysqldata:/var/lib/mysql
networks:
- dbnet
elasticsearch:
image: elasticsearch:5.3
container_name: elasticsearch
depends_on:
mysql:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
interval: 30s
timeout: 30s
retries: 3
environment:
- "ES_JAVA_OPTS=-Xmx2g -Xms2g"
- bootstrap.memory_local=true
- cluster.name=adlp-cluster
ports:
- 19200:9200
- 19300:9300
volumes:
- ./elasticsearch/config/elasticsearch.yml:/etc/elasticsearch/config/elasticsearch.yml
- ./elasticsearch/config/jvm.options:/etc/elasticsearch/config/jvm.options
- ./elasticsearch/config/log4j2.properties:/etc/elasticsearch/config/log4j2.properties
- esdata:/usr/share/elasticsearch/data
networks:
- esnet
kibana:
image: kibana:5.3
container_name: kibana
depends_on:
elasticsearch:
condition: service_healthy
ports:
- "5601:5601"
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
- XPACK_MONITORING_ENABLED=false
depends_on:
- elasticsearch
networks:
- esnet
volumes:
mysqldata:
driver: local
esdata:
driver: local
networks:
esnet:
driver: bridge
dbnet:
driver: bridge
@shavo007
Copy link
Author

shavo007 commented Jun 8, 2017

Finally, for debugging health checks, the Docker inspect command lets you view the output of commands that succeed or fail (here in JSON format):

docker inspect --format='{{json .State.Health}}' elasticsearch

@shavo007
Copy link
Author

shavo007 commented Jun 8, 2017

After the container image is rebuilt and run, the health state is returned in parentheses in the output of docker ps

@inigoreiriz
Copy link

how does elasticsearch communicate with mysql? They are in 2 different networks. Shouldn't container elasticsearch belong to both esnet and dbnet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment