参考资料: https://ken.io/note/kafka-standalone-docker-install
Windows Docker 桌面版: https://docs.docker.com/desktop/install/windows-install/
Docker Compose部署Kafka
1、创建Docker Compose配置文件
使用Docker Compose可以将一系列创建及映射资源(网络、数据卷等)操作放在配置文件中,并且可以通过depends_on参数指定容器的启动顺序,通过environment参数指定Kafka需要的基本参数信息
创建kafka-group.yml,保存以下信息
version: '3'
name: kafka-group
services:
zookeeper-test:
image: zookeeper
ports:
- "2181:2181"
volumes:
- zookeeper_vol:/data
- zookeeper_vol:/datalog
- zookeeper_vol:/logs
container_name: zookeeper-test
kafka-test:
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: "localhost"
KAFKA_ZOOKEEPER_CONNECT: "zookeeper-test:2181"
KAFKA_LOG_DIRS: "/kafka/logs"
volumes:
- kafka_vol:/kafka
depends_on:
- zookeeper-test
container_name: kafka-test
volumes:
zookeeper_vol: {}
kafka_vol: {}
2、启动容器组
# 启动Kafka容器组
docker compose -f kafa-group.yml up -d
# 输出示例
✔ Network kafka-group_default Created
✔ Volume "kafka-group_zookeeper_vol" Created
✔ Volume "kafka-group_kafka_vol" Created
✔ Container zookeeper-test Started
✔ Container kafka-test Started
关于电脑重启后无法重新启动的问题
解决方案,清空 Vol 后再重启