docker-compse 启动文件
version: '3'
name: kafka1
services:
zookeeper:
image: bitnami/zookeeper:latest
ports:
- "2181:2181"
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
# volumes:
# - zookeeper_vol:/data
# - zookeeper_vol:/datalog
# - zookeeper_vol:/logs
container_name: zookeeper
kafka:
image: bitnami/kafka:latest
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: "localhost"
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
# KAFKA_LOG_DIRS: "/home"
# volumes:
# - kafka_vol:/kafka
depends_on:
- zookeeper
container_name: kafka
#volumes:
# zookeeper_vol: {}
# kafka_vol: {}
启动一个命令行,生产
docker-compose -f kafa-group.yml up -d
docker exec -it kafka /bin/bash
cd /opt/bitnami/kafka/bin
sh kafka-console-producer.sh --broker-list localhost:9092 --topic test
另开一个命令行,消费
docker exec -it kafka /bin/bash
cd /opt/bitnami/kafka/bin
sh kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test
在生产中输入字符
消费端接收到