环境
Ubuntu 20.04
docker 19.03.13
docker-compose 1.25.0
compose文件
不废话,直接上配置文件。
version: '3.7'
services:
cerebro:
image: lmenezes/cerebro
container_name: cerebro
ports:
- "9000:9000"
command:
- -Dhosts.0.host=http://elasticsearch:9200
networks:
- es7net
kibana:
image: kibana:7.9.3
container_name: kibana
environment:
- I18N_LOCALE=zh-CN
- XPACK_GRAPH_ENABLED=true
- TIMELION_ENABLED=true
- XPACK_MONITORING_COLLECTION_ENABLED="true"
ports:
- "5601:5601"
networks:
- es7net
logstash:
image: logstash:7.9.3
container_name: logstash
ports:
- 4560:4560
networks:
- es7net
elasticsearch:
image: elasticsearch:7.9.3
container_name: es7
environment:
- cluster.name=es7
- xpack.security.enabled=false
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" #jvm内存分配为512MB
- "discovery.type=single-node" #单节点启动
- "TZ=Asia/Shanghai"
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
volumes:
- es7data1:/usr/share/elasticsearch/data
- es7log1:/usr/share/elasticsearch/logs
ports:
- 9200:9200
networks:
- es7net
volumes:
es7data1:
driver: local
es7log1:
driver: local
es7logstash:
driver: local
networks:
es7net:
driver: bridge
参数说明
version: '3.7'
这是指compose文件对应的docker引擎版本,不是乱填的,官方链接
services:
cerebro:
image: lmenezes/cerebro
container_name: cerebro
ports:
- "9000:9000"
command:
- -Dhosts.0.host=http://elasticsearch:9200
networks:
- es7net
cerebro是ElasticSearch监控工具,如果不用,可以去掉。
command是覆盖容器启动的默认命令。
networks是配置容器连接的网络,因为docker将应用相互隔离了,需要指定网络通信。
kibana:
image: kibana:7.9.3
container_name: kibana
environment:
- I18N_LOCALE=zh-CN
- XPACK_GRAPH_ENABLED=true
- TIMELION_ENABLED=true
- XPACK_MONITORING_COLLECTION_ENABLED="true"
ports:
- "5601:5601"
networks:
- es7net
environment添加环境变量。
elasticsearch:
image: elasticsearch:7.9.3
container_name: es7
environment:
- cluster.name=es7
- xpack.security.enabled=false
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" #jvm内存分配为512MB
- "discovery.type=single-node" #单节点启动
- "TZ=Asia/Shanghai"
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
volumes:
- es7data1:/usr/share/elasticsearch/data
- es7log1:/usr/share/elasticsearch/logs
ports:
- 9200:9200
networks:
- es7net
ulimits指定容器的ulimits限制值,例如,指定最大进程数为65535,指定文件句柄数位20000(软限制,应用可以随时修改,不能超过硬限制,只能root用户提高)。
volumes将主机的数据卷或者文件挂载到容器里。
运行
docker-compose -f xxxx(配置文件) up -d
up选项启动容器,使用-f(或--file)选项来指定Dockerfile,使用-d选项以守护模式运行,镜像如果没有,docker会先拉取镜像,有则直接创建并启动容器,注意文件运行前不能有其同名容器。
网友评论