docker 安装常用中间件

目录

  • 1.docker指令
    • 1.1 停止并删除容器
    • 1.2 指定网络、指定网络别名、后台运行、端口映射、入口指令
  • 2.常用中间件docker部署
    • 2.1.前提:创建公用网络
    • 2.2.zookeeper
      • 2.2.1.启动
      • 2.2.2.连接
    • 2.3.kafka
      • 2.3.1.启动
      • 2.3.2.连接
        • 2.3.3.创建topic
        • 2.3.4查看topic
        • 2.3.5生产消息
        • 2.3.6消费消息
    • 2.4.mysql
      • 2.4.1.启动
      • 2.4.2.连接
    • 2.5.redis
      • 2.5.1启动
      • 2.5.2.连接
    • 2.6.minio
      • 2.6.1.启动
      • 2.6.2.连接
    • 2.7.xxljob
      • 2.7.1.启动
      • 2.7.2.连接
    • 2.8 rocket mq
      • 2.8.1启动
      • 2.8.2 打开console
      • 2.8.3 停止
  • 3.常用中间件docker-compose部署

1.docker指令

1.1 停止并删除容器

docker rm -f cid

1.2 指定网络、指定网络别名、后台运行、端口映射、入口指令

docker --network my_net --network-alias net1 -d -p 8080:8080 -v local_dir:container_dir image entry_command entry_command_sub

2.常用中间件docker部署

2.1.前提:创建公用网络

docker network create common

2.2.zookeeper

2.2.1.启动

docker run --name zookeeper --restart always -d -p 2181:2181  \
--network common --network-alias zwb-zookeeper zookeeper

2.2.2.连接

docker run --network common  -it --rm zookeeper zkCli.sh -server zwb-zookeeper

2.3.kafka

2.3.1.启动

docker run -d --name kafka-server \
    --network common -p 9092:9092\
    -e ALLOW_PLAINTEXT_LISTENER=yes \
    -e KAFKA_CFG_LISTENERS=PLAINTEXT://:9092\
    -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092\
    -e KAFKA_CFG_ZOOKEEPER_CONNECT=zwb-zookeeper:2181 \
    bitnami/kafka:latest

2.3.2.连接

2.3.3.创建topic

docker run -it --rm \
    --network common \
    -e KAFKA_CFG_ZOOKEEPER_CONNECT=zwb-zookeeper:2181 \
    bitnami/kafka:latest kafka-topics.sh --create  --topic  zwb-topic --replication-factor 1 --partitions 1  --zookeeper zwb-zookeeper:2181

2.3.4查看topic

docker run -it --rm \
    --network common \
    -e KAFKA_CFG_ZOOKEEPER_CONNECT=zwb-zookeeper:2181 \
    bitnami/kafka:latest kafka-topics.sh --list  --zookeeper zwb-zookeeper:2181

2.3.5生产消息

#!/bin/bash
docker run -it --rm \
    --network common \
    bitnami/kafka:latest kafka-console-consumer.sh --bootstrap-server kafka-ip:9092 --topic your-topic --from-beginning
#如遇报错,并且本机有安装过多版本的zookeeper,那么可能是zk缓存问题,删除/tmp/zookeeper目录内容或许可以解决

2.3.6消费消息

#!/bin/bash
docker run -it --rm \
    --network common \
    bitnami/kafka:latest kafka-console-producer.sh --bootstrap-server 192.168.31.170:9092 --topic your-topic

2.4.mysql

2.4.1.启动


docker run -v ~/myShells/docker/mysql/data:/var/lib/mysql  --name mysql --network common --network-alias zwb-mysql -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0

允许远程ip登陆
update mysql.user set host = ‘%’ where user =‘root’;
flush privileges;

2.4.2.连接

docker run -it --network common --rm mysql mysql -hzwb-mysql -uroot -pzwb_pwd

2.5.redis

2.5.1启动

docker run --name redis --network common  -p 6379:6379 --network-alias zwb-redis  -d  redis --requirepass "123456"

2.5.2.连接

docker run -it --rm --network common redis redis-cli -h zwb-redis

2.6.minio

2.6.1.启动

docker run -d -p 9000:9000 -p 9001:9001  \
-v ~/myShells/docker/minio/data:/data  \
-v ~/myShells/docker/minio/conf:/root/.minio\
--name minio \
-e "MINIO_ACCESS_KEY=admin" \
-e "MINIO_SECRET_KEY=admin123"\
minio/minio server /data -console-address ":9001"

2.6.2.连接

docker run -v ~/docker/minio/mc_config:/root/.mc/ -it --entrypoint=/bin/sh minio/mc

2.7.xxljob

2.7.1.启动

docker run --network common -e PARAMS="--spring.datasource.url=jdbc:mysql://zwb-mysql:3306/xxl_job?Unicode=true&characterEncoding=UTF-8&useSSL=false --spring.datasource.username=root --spring.datasource.password=123456 --xxl.admin.login=false" \
 -p 9080:8080  --name xxl-job-admin \
 -d xuxueli/xxl-job-admin:2.1.2

需要执行db初始化脚本

2.7.2.连接

访问 http://127.0.0.1:9080/xxl-job-admin/

2.8 rocket mq

2.8.1启动

下载git项目

#!/bin/bash
cd ./docker-rocketmq/rmq
./start.sh

2.8.2 打开console

#!/bin/bash
open http://localhost:8180/#/

2.8.3 停止

#!/bin/bash
cd /Users/wenbin.zheng/myShells/docker/rocketmq/docker-rocketmq/rmq
./stop.sh

3.常用中间件docker-compose部署

version: "3.7"
services:
 compose-zookeeper:
  image: zookeeper
  networks:
   common:
    aliases:
     - zwb-zookeeper
  ports:
   - 2181:2181
  compose-kafka:
    environment:
      ALLOW_PLAINTEXT_LISTENER: "true"
      KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://192.168.31.170:9092
      KAFKA_CFG_LISTENERS: PLAINTEXT://:9092
      KAFKA_CFG_ZOOKEEPER_CONNECT: zwb-zookeeper:2181
    image: bitnami/kafka
    depends_on: 
      - compose-zookeeper
    networks:
      common:
        aliases:
          - zwb-kafka
    ports:
      - 9092:9092
  compose-mysql:
    cap_add:
      - SYS_NICE
    environment:
      MYSQL_ROOT_PASSWORD: 123456
    image: mysql:8.0
    networks:
      common:
        aliases:
          - zwb-mysql
    ports:
      - 3307:3306
    volumes:
      - ~/myShells/docker/mysql/data:/var/lib/mysql
  compose-redis:
    command: redis-server --requirepass "123456"
    image: redis
    networks:
      common:
        aliases:
          - zwb-redis
    ports:
      - 6379:6379

  compose-minio:
    environment:
      MINIO_ACCESS_KEY: admin
      MINIO_SECRET_KEY: admin123
    image: minio/minio
    command: server /data -console-address ":9001"
    networks:
      common:
        aliases:
          - zwb-minio
    ports:
      - 9000:9000
      - 9001:9001
    volumes:
      - ~/myShells/docker/minio/data:/data
      - ~/myShells/docker/minio/conf:/root/.minio
  compose-xxljob:
    environment:
      PARAMS: --spring.datasource.url=jdbc:mysql://zwb-mysql:3306/xxl_job?Unicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true --spring.datasource.username=root --spring.datasource.password=123456 --xxl.admin.login=false
      MINIO_SECRET_KEY: admin123
    image: xuxueli/xxl-job-admin:2.1.2
    depends_on: 
      - compose-mysql
    networks:
      common:
        aliases:
          - zwb-xxljob
    ports:
      - 9080:8080
networks:
  common:

你可能感兴趣的:(linux,docker,mysql,kafka,minio,redis)