【Docker】docker-compose常用的构建docker容器的yml文件

docker-compose的简单使用方法,在准备好的文件夹中,mkdir好要挂载的如data或者conf文件夹,及vim docker-compose.yml,将下方的要使用的内容粘贴进去,根据自己需要添加/删除/修改一下。最后在当前文件夹直接后台启动即可,docker-compose up -d

mysql 5.7

mysql 5.7[1]

version: '3'
services:
  mysql:
    restart: always
    image: mysql:5.7.16
    container_name: mysql-01
    #冒号左侧是宿主机目录,右侧是docker容器中的目录
    volumes:
      - ./data:/var/lib/mysql
      - ./conf/my.cnf:/etc/my.cnf
    environment:
      - "MYSQL_ROOT_PASSWORD=123456"
      - "MYSQL_DATABASE=test"
      - "TZ=Asia/Shanghai"
    ports:
      - 3306:3306

mysql 8

mysql8的挂载有一些区别

version: '3'
services:
  mysql:
    restart: always
    image: mysql:8.0.36
    container_name: mysql-02
    volumes:
      - ./data:/var/lib/mysql
      - ./conf/my.cnf:/etc/mysql/conf.d
      - ./logs:/logs
    environment:
      - "MYSQL_ROOT_PASSWORD=123456"
      - "MYSQL_DATABASE=test"
      - "TZ=Asia/Shanghai"
    ports:
      - 3306:3306

rabbitmq

rabbitmq

version: '3.1'
services:
  rabbitmq:
    restart: always
    image: daocloud.io/library/rabbitmq:3.8.8
    volumes:
      - ./data/:/var/lib/rabbitmq/
      - ./log/:/var/log/rabbitmq/log/
    ports:
      - 15672:15672
      - 5672:5672

rabbitmq开启可视化界面:

/opt/rabbitmq//sbin/rabbitmq-plugins enable rabbitmq_management

elasticsearch

elasticsearch(elk[3])
docker-compose.yml文件

version: '3.1'
services:
  elk_elasticsearch:
    image: elasticsearch:7.8.1
    container_name: elk_elasticsearch
    restart: always
    environment:
      - discovery.type=single-node
      - ES_JAVA_OPTS=-Xms4096m -Xmx4096m
    ports:
      - 9200:9200 
      - 9300:9300 
    volumes:
      # 授权 chmod 777 ./config/ && chmod 777 ./data/
      - ./data:/usr/share/elasticsearch/data
      - ./config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    networks:
      - devopsnetwork

networks:
  devopsnetwork:
    external: true

config目录中elasticsearch.yml

network.host: 0.0.0.0
xpack:
  ml.enabled: false
  monitoring.enabled: false
  security.enabled: false
  watcher.enabled: false

给目录授权

chmod 777 ./config/ && chmod 777 ./data/

ELK 的版本为 v7.8.1,本篇使用的容器网络为 devopsnetwork ,需创建

docker network create devopsnetwork

logstash

docker-compose.yml

version: '3.1'
services:
  elk_logstash:
    image: logstash:7.17.16
    container_name: elk_logstash
    restart: always
    ports:
      - 5044:5044 
    volumes:
     # 授权 chmod 777 ./logs/ && chmod 777 ./data/ && chmod 777 ./pipeline/ && chmod 777 ./config/ 
      - /etc/timezone:/etc/timezone
      - /etc/localtime:/etc/localtime:ro
      - ./logs:/usr/share/logstash/logs
      - ./data:/usr/share/logstash/data
      - ./pipeline:/usr/share/logstash/pipeline
      - ./config:/usr/share/logstash/config
    networks:
      - devopsnetwork

networks:
  devopsnetwork:
    external: true

pipeline目录下logstash.conf

input {
    beats {
        port => 5044
        codec => json {
            charset => "UTF-8"
        }
    }

}

filter {  
 
}

output {
    elasticsearch { 
      hosts => ["http://192.168.123.102:9200"]
      index => "%{[app]}-%{+YYYY.MM.dd}" 
  }    
  stdout { 
    codec => rubydebug 
  }
}

给目录授权

chmod 777 ./logs/ && chmod 777 ./data/ && chmod 777 ./pipeline/ && chmod 777 ./config/ 

kibana

docker-compose.yml

version: '3.1'
services:
  elk_kibana:
    image: kibana:7.8.1
    container_name: elk_kibana
    restart: always
    environment:
      - discovery.type=single-node
    ports:
      - 5601:5601 
    volumes:
      - ./config/kibana.yml:/usr/share/kibana/config/kibana.yml
    networks:
      - devopsnetwork

networks:
  devopsnetwork:
    external: true

config目录下kibana.yml

server.host: "0.0.0.0"
elasticsearch.hosts: ["http://192.168.123.102:9200/"]
i18n.locale: "zh-CN"
xpack:
  apm.ui.enabled: false
  graph.enabled: false
  ml.enabled: false
  monitoring.enabled: false
  reporting.enabled: false
  security.enabled: false
  grokdebugger.enabled: false
  searchprofiler.enabled: false

yapi[4]

version: "3.5"
services:
  mongodb:
    container_name: mongodb
    image: mongo:latest
    restart: always
    ports:
      - 27017:27017
    environment:
      - MONGO_INITDB_ROOT_USERNAME=jobs
      - MONGO_INITDB_ROOT_PASSWORD=123456
    volumes:
      - ./mongodb_data:/data/db
    networks:
      - yapi_net
    # 增加启动参数,--auth,表示连接 mongodb 需要用户名和密码
    command:
      - "--auth"
 
  yapi:
    image: jayfong/yapi:latest
    container_name: yapi
    restart: always
    ports:
      - 3000:3000
    environment:
      # 随便设置一个账号(账号是邮箱的格式)
      - YAPI_ADMIN_ACCOUNT=root.com
      # 设置账号的密码
      - YAPI_ADMIN_PASSWORD=root
      # 禁用注册功能
      - YAPI_CLOSE_REGISTER=true
      # 设置连接 mongdb 的服务器地址,可以使用容器内部的 mongodb 服务名称
      - YAPI_DB_SERVERNAME=mongodb
      - YAPI_DB_PORT=27017
      - YAPI_DB_DATABASE=yapidb
      - YAPI_DB_USER=jobs
      - YAPI_DB_PASS=123456
      - YAPI_DB_AUTH_SOURCE=admin
      #- YAPI_DB_CONNECT_STRING="mongodb://jobs:123456@mongodb:27017/yapidb?authSource=admin"
      # 禁用发送邮件的功能
      - YAPI_MAIL_ENABLE=false
      # 禁用 LDAP 登录功能
      - YAPI_LDAP_LOGIN_ENABLE=false
      # 不使用任何插件
      - YAPI_PLUGINS=[]
    networks:
      - yapi_net
    depends_on:
      - mongodb
 
networks:
  yapi_net:
    driver: bridge

其端口为3000,ip:3000即可访问到yapi的首页

参考文章:
[1],使用docker-compose配置mysql服务
[2],使用 Docker Compose 部署 MySQL 8.0
[3],使用 Docker Compose V2 快速搭建日志分析平台 ELK (Elasticsearch、Logstash 和 Kibana)
[4],使用 docker-compose 部署和使用 Yapi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值