侧边栏壁纸
  • 累计撰写 793 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索

目 录CONTENT

文章目录

compose

Dettan
2021-07-10 / 0 评论 / 0 点赞 / 168 阅读 / 698 字
温馨提示:
本文最后更新于 2022-07-23,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
官方文档
可选参数

compose是一个定义和运行多个容器的工具.
使用yaml文件定义
一行命令启动.
使用mvm install 的镜像
version: '3'
services:
  #消息中心
  bus-server:
    image: cike/bus-server:latest
    container_name: sc-bus
    restart: always
    networks:
      - sc-net
    ports:
      - 8071:8071
    env_file: .env
    environment:
      TZ: Asia/Shanghai
links
skywalking-oap:
    image: wutang/skywalking-oap:6.1.0
    container_name: skywalking-oap
    networks:
      - sc-net
    depends_on:
      - elasticsearch
    links:
      - elasticsearch
    restart: always
    ports:
      - 11800:11800
      - 12800:12800
    volumes:
      - ./devops/skywalking/config:/apache-skywalking-apm-bin/config:ro
elasticsearch:
    image: elasticsearch:5.6-alpine
    container_name: sc-elasticsearch
    restart: always
    environment:
      - cluster.name=elasticsearch
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
      - node.name=elasticsearch_node_1
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - ../data/elasticsearch/data:/usr/share/elasticsearch/data
      - ../data/elasticsearch/logs:/usr/share/elasticsearch/logs
      - ./devops/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    networks:
      - sc-net
    ports:
      - 9200:9200
      - 9300:9300
示例 : 启动 nacos
version: '3'
services:
  nacos:
    image: nacos/nacos-server:1.1.3
    container_name: sc-nacos-standalone
    networks:
      - sc-net
    environment:
      - PREFER_HOST_MODE=hostname
      - MODE=standalone
    volumes:
      - ../data/nacos-server/logs/:/home/nacos/logs
    ports:
      - "8848:8848"

  prometheus:
    container_name: sc-prometheus
    image: prom/prometheus:latest
    networks:
      - sc-net
    volumes:
      - ./nacos/prometheus.yaml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"
    depends_on:
      - nacos
    restart: on-failure
示例 : 启动 redis , rabbitmq , mysql 并初始化 mysql数据库.
version: '3'
services:
  redis: 
    image: redis:alpine
    container_name: sc-redis
    restart: always
    volumes:
      - ../data/redis:/data
    environment:
      - REDIS_PASSWORD=123456
    networks:
      - sc-net
    ports:
      - 6379:6379
    env_file: .env

  rabbitmq:
    image: rabbitmq:management-alpine
    container_name: sc-rabbitmq
    restart: always
    volumes:
      - ../data/rabbitmq:/var/lib/rabbitmq/mnesia
    networks:
      - sc-net
    ports:
      - 5672:5672
      - 15672:15672
    env_file: .env

  mysql:
    image: mysql:5.7
    container_name: sc-mysql
    restart: always
    networks:
      - sc-net
    ports:
      - 3306:3306
    volumes:
      - ../data/mysql:/var/lib/mysql
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: root123

  mysql-init:
    image: mysql:5.7
    command: /init-db.sh
    networks:
      - sc-net
    volumes:
      - ../auth/db:/sql/auth
      - ../gateway/gateway-admin/src/main/db:/sql/gateway
      - ../sysadmin/db:/sql/sysadmin
      - ./init-db.sh:/init-db.sh
    environment:
      MYSQL_ROOT_PASSWORD: root123

networks:
  sc-net:
    external: false

.env
## docker-compose环境变量

### 数据源postgres实例
#DATASOURCE_DBTYPE=postgresql
#DATASOURCE_HOST=postgres
#DATASOURCE_PORT=5432
#DATASOURCE_USERNAME=postgres
#DATASOURCE_PASSWORD=postgres
#DATASOURCE_DRIVER=org.postgresql.Driver

### 数据源mysql实例
DATASOURCE_DBTYPE=mysql
DATASOURCE_HOST=mysql
DATASOURCE_PORT=3306
DATASOURCE_USERNAME=root
DATASOURCE_PASSWORD=root123
DATASOURCE_DRIVER=com.mysql.jdbc.Driver

### 分布式缓存
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=123456

### 消息中间件
RABBIT_MQ_HOST=rabbitmq
RABBIT_MQ_PORT=5672
RABBIT_MQ_USERNAME=guest
RABBIT_MQ_PASSWORD=guest

### 注册中心
REGISTER_HOST=nacos
REGISTER_PORT=8848

### sentinel dashboard
SENTINEL_DASHBOARD_HOST=sentinel-dashboard
SENTINEL_DASHBOARD_PORT=8021

### MOSS
MOSS_DB_TYPE=mysql
MOSS_PORT=8086
MOSS_SKYWALKING_HOST=skywalking-oap
MOSS_SKYWALKING_PORT=12800

### skywalking-agent 容器内路径
SW_AGENT_OPTS=-javaagent:/skywalking/agent/skywalking-agent.jar -Dskywalking.collector.backend_service=localhost:11800 -Dskywalking.agent.service_name

### kong数据库
KONG_ADMIN_LISTEN=0.0.0.0:8001
KONG_ADMIN_LISTEN_SSL=0.0.0.0:8444
KONG_CASSANDRA_CONTACT_POINTS=mysql
KONG_DATABASE=sc_gateway_kong
KONG_PG_HOST=mysql

### konga数据库
TOKEN_SECRET=123456
DB_ADAPTER:=mysql
DB_USER=root
DB_PASSWORD=root123
DB_DATABASE=sc_gateway_konga
DB_PG_SCHEMA=public
NODE_ENV=production
DB_HOST=mysql
DB_PORT=3306

init-db.sh
#!/usr/bin/env bash

for file in $(find /sql -name "*.sql" -exec ls {} \;| grep -v postgres | sort | tr ' ' '|' | tr '\n' ' ')
do
    file=$(echo ${file} | tr '|' ' ')
    printf "Applying update ${file}\n"
    mysql -uroot -p$MYSQL_ROOT_PASSWORD -h mysql < ${file}
done




0

评论区