标签:arch automatic stop 通过 kibana mod cat work driver
Docker-compose管理docker服务
1、安装docker-compose
@首先确保服务器上已经安装docker环境,如果没有安装使用如下命令进行安装:
# yum -y install dock
#curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose
2、创建docker-compose运行需要的配置文件,docker-compose.yml他是yml格式的。默认启动的时候会在当前目录下找配置文件,也可以通过-f 指定配置文件来启动。
# cat docker-compose.yml
version: ‘2‘
services:
elasticsearch:
build: elasticsearch/
ports:
- "9200:9200"
- "9300:9300"
environment:
ES_JAVA_OPTS: "-Xms30g -Xmx30g"
networks:
- docker_elk
volumes:
- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /data/elasticsearch:/usr/share/elasticsearch/data
logstash:
build: logstash/
command: -f /etc/logstash/conf.d/ --config.reload.automatic
volumes:
- ./logstash/config:/etc/logstash/conf.d
ports:
- "5000:5000"
- "5043:5043"
networks:
- docker_elk
depends_on:
- elasticsearch
kibana:
build: kibana/
volumes:
- /tmp/:/etc/archives/
- ./kibana/config/:/etc/kibana/
ports:
- "5601:5601"
networks:
- docker_elk
depends_on:
- elasticsearch
networks:
docker_elk:
driver: bridge
@这个配置文件使用解读如下:
services:
部署的服务名称:
build: 填写服务的Dockerfile路径
ports:
- “本机port:容器port”
- “………”
- …………….
注:当使用 HOST:CONTAINER 格式来映射端口时,如果你使用的容器端口小于 60 你可能会得到错误得结果,因为 YAML 将会解析 xx:yy 这种数字格式为 60 进制。所以建议采用字符串格式。
environment: 设置环境变量
ES_JAVA_OPTS: "-Xms30g -Xmx30g"
networks: 定义docker网络,名称一样的可以互通。
- “docker_elk”
volumes: 挂载本地目录到容器
- /data:/data
command: -f /etc/logstash/conf.d/ --config.reload.automatic
command用于覆盖容器后执行的命令
networks:
docker_elk:
driver:bridge
extends: 基于已有的服务进行扩展
file: common.yml
使用这种方式管理docker容器,前提必须已经创建好了Dockerfile,在相应的目录下。
@第二种格式是docker-compose自己pull镜像,不用创建Dockerfile
# cat docker-compose.yml
version: ‘2‘
services:
App1:
image: nginx #指定为镜像名称或镜像 ID。如果镜像在本地不存在,Compose 将会尝试拉去这个镜像。
ports:
- "8080:80"
networks:
- "netName1"
volumes:
- /opt/conf/:/mnt
App2:
image: nginx
ports:
- "8081:80"
networks:
- "netName1"
volumes:
- /opt/conf/nginx.conf:/etc/nginx/nginx.conf
App3:
image: nginx
- /opt/web/:/usr/share/nginx/html
ports:
- "8082:80"
networks:
- "netName2"
networks:
netName1:
driver: bridge
netName2:
driver: bridge
启动服务:
# docker-compose up -d
# docker-compose ps
# docker-compose exec App1 bash
# docker-compose restart App1
# docker-compose stop App1
# docker-compose stop
# docker-compose start
标签:arch automatic stop 通过 kibana mod cat work driver
原文地址:http://www.cnblogs.com/cuishuai/p/7207263.html