docker compose启动常用服务

MySQL

version: '3.1'
services:
  mysql: # 服务的名称
    restart: always  # 代表只要docker启动,那么这个容器就跟着一起启动
    image: daocloud.io/library/mysql:5.7.4  # 指定镜像路径
    container_name: mysql  # 指定容器名称
    ports:
      - 3306:3306 # 指定端口号的映射
    environment:
      MYSQL_ROOT_PASSWORD: root # 指定MySQL的ROOT用户登录密码
      TZ: Aisa/Shanghai # 指定时区
    volumes:
      - /opt/docker_mysql/data:/var/lib/mysql # 映射数据卷

RabbitMQ

version: "3.1"
services:
  rabbitmq:
    image: daocloud.io/library/rabbitmq:management
    restart: unless-stopped
    container_name: rabbitmq
    ports:
      - 5672:5672
      - 15672:15672
    volumes:
      - ./data:/var/lib/rabbitmq

kafka

version: '3.5'
services:
  zookeeper:
    image: wurstmeister/zookeeper                  # 镜像
    container_name: zookeeper
    ports:
      - "2181:2181"                                # 对外暴露的端口号
  kafka:
    image: wurstmeister/kafka                      # 镜像
    container_name: kafka
    volumes: 
        - /opt/docker_kafka/data:/var/lib/kafka    # 挂载位置
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 42.192.6.39      # 宿主机IP -- client 要访问的broker地址
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181      # kafka运行是基于 zookeeper 的,通过端口连接zookeeper
      KAFKA_BROKER_ID: 0                           # 每个容器就是一个 broker,设置器对应的ID
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_LOG_RETENTION_HOURS: 120
      KAFKA_MESSAGE_MAX_BYTES: 10000000
      KAFKA_REPLICA_FETCH_MAX_BYTES: 10000000
      KAFKA_GROUP_MAX_SESSION_TIMEOUT_MS: 60000
      KAFKA_NUM_PARTITIONS: 3
      KAFKA_DELETE_RETENTION_MS: 1000
      KAFKA_LOG_DIRS: "/kafka/logs"                # 设置 kafka 日志位置
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'      # kafka 自动创建 topic,对于生产者与消费者连接的 TOPIC 不存在自动创建
      KAFKA_DELETE_TOPIC_ENABLE: 'true'            # kafka 开启删除 topic,开了自动创建,删除的也要开,否则删除后还会自动创建
  kafka-manager:
    image: sheepkiller/kafka-manager               # 镜像:开源的web管理kafka集群的界面
    container_name: kafka-manager
    environment:
        ZK_HOSTS: 42.192.34.125                      # 修改:宿主机IP
    ports:  
      - "9009:9000"                                # 暴露端口 9000这个端口冲突太多

mongoDB

version: '3.1'
services:
  mongodb:
    image: daocloud.io/library/mongo:2.7.6
    container_name: mongodb
    volumes:
      - ./data/mongod.conf:/etc/mongod.conf
      - ./data/db:/data/db
      - ./data/logs:/data/logs
    ports:
      - 27017:27017
    restart: always
    command: mongod --auth
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=root

Nginx

version: '3.1'
services:
  nginx:
    restart: always
    image: daocloud.io/library/nginx:1.12.0-alpine
    container_name: nginx
    ports:
      - 80:80
    volumes:
      - /opt/docker_nginx/conf.d/:/etc/nginx/conf.d

Redis

 

 

 

version: '3.8'
services:
  myredis:
    container_name: myredis
    image: redis:6.0.6
    restart: always
    ports:
      - 6379:6379
    privileged: true
    command: redis-server /etc/redis/redis.conf --appendonly yes
    volumes:
      - $PWD/data:/data
      - $PWD/conf/redis.conf:/etc/redis/redis.conf
    networks:
      - myweb
 
networks:
 
  myweb:
    driver: bridge

手动创建 redis.conf

#开启保护
protected-mode yes
#开启远程连接 
#bind 127.0.0.1 
#自定义密码
requirepass 12345678 
port 6379
timeout 0
# 900s内至少一次写操作则执行bgsave进行RDB持久化
save 900 1 
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /data
appendonly yes
appendfsync everysec

 

 

docker-compose 安装redis 详解

https://blog.csdn.net/u010141170/article/details/126471309

posted @ 2022-09-21 16:37  wq9  阅读(546)  评论(0编辑  收藏  举报