Docker-compose常用软件部署(mysql、redis、rabbitmq)

shenzhenzsw 2020-07-18

Docker-compose常用软件部署(mysql、redis、rabbitmq)

废话不多说,下面就直接给出部署文件已经启动脚本,这个会持续更新。以下的部署方式均是单例部署。高可用或者其他部署方案我会单独写相应的文章。

  • mysql数据库
  • redis缓存
  • rabbitmq消息队列

compose-mysql.yaml

version: ‘3‘

# docker network create mysql_bridge
networks:
  mysql_bridge:
    driver: bridge

services:
   mysql-server:
     image: docker.io/mysql:5.7
     container_name: mysql-server
     restart: always
     environment:
       # 指定root密码。不指定则会启动失败
       - MYSQL_ROOT_PASSWORD:123456
     volumes:
       # 同步本地时间
       - /etc/localtime:/etc/localtime:ro
       # 初始化执行的sql
       # - ./init:/docker-entrypoint-initdb.d/
       # db配置
       - ./conf/my.cnf:/etc/my.cnf
       # db文件存放地址
       - ./db_data:/var/lib/mysql
     ports:
       - 3306:3306
     networks:
       - mysql_bridge

start-mysql.sh

#! /usr/bin/bash
# 定义一个名称变量
network_name="mysql_bridge"

filterName=`docker network ls | grep $network_name | awk ‘{ print $2 }‘`

if [ "$filterName" == "" ]; then
    # 不存在就创建
    docker network create $network_name
    echo "Created network $network_name success!!"
fi

docker-compose -f ./compose-mysql.yaml up -d
docker ps -a
docker logs -f mysql-server

compose-redis.yaml

version: ‘3‘

# docker network create redis_bridge
networks:
  redis_bridge:
    driver: bridge
    
services:
   redis-server:
     image: docker.io/redis:latest
     container_name: redis-server
     restart: always
     command: redis-server --requirepass "123456"
     volumes:
        - /etc/localtime:/etc/localtime:ro
        - ./redis_data:/var/lib/redis
     ports:
       - 6379:6379
     networks:
       - redis_bridge

start-redis.sh

#! /usr/bin/bash
# 定义一个名称变量
network_name="redis_bridge"

filterName=`docker network ls | grep $network_name | awk ‘{ print $2 }‘`

if [ "$filterName" == "" ]; then
    # 不存在就创建
    docker network create $network_name
    echo "Created network $network_name success!!"
fi

docker-compose -f ./compose-redis.yaml up -d
docker ps -a
docker logs -f redis-server

compose-rabbitmq.yaml

version: ‘3‘

# docker network create rabbitmq_bridge
networks:
  rabbitmq_bridge:
    driver: bridge
    
services:
  rabbitmq:
    image: rabbitmq:management-alpine
    container_name: rabbitmq-server
    restart: always
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./data:/var/lib/rabbitmq
    environment:
      - RABBITMQ_DEFAULT_USER=ming
      - RABBITMQ_DEFAULT_PASS=ming123456
    ports:
      - "15672:15672"
      - "5672:5672"
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"
    networks:
      - rabbitmq_bridge

start-rabbitmq.sh

#! /usr/bin/bash
# 定义一个名称变量
network_name="rabbitmq_bridge"

filterName=`docker network ls | grep $network_name | awk ‘{ print $2 }‘`

if [ "$filterName" == "" ]; then
    # 不存在就创建
    docker network create $network_name
    echo "Created network $network_name success!!"
fi

docker-compose -f ./compose-rabbitmq.yaml up -d
docker ps -a
docker logs -f rabbitmq-server

相关推荐