1. 下载镜像
//下载zookeeper
docker pull wurstmeister/zookeeper
//下载kafka
docker pull wurstmeister/kafka:2.11-0.11.0.3
2.启动镜像
//启动zookeeper
docker run -d --name zookeeper --publish 2181:2181 --volume /etc/localtime:/etc/localtime wurstmeister/zookeeper
//启动kafka
docker run -d --name kafka --publish 9092:9092 \
--link zookeeper \
--env KAFKA_ZOOKEEPER_CONNECT=192.168.121.205:2181 \
--env KAFKA_ADVERTISED_HOST_NAME=192.168.121.205 \
--env KAFKA_ADVERTISED_PORT=9092 \
--volume /etc/localtime:/etc/localtime \
wurstmeister/kafka:2.11-0.11.0.3
3.测试kafka
//创建topic
bin/kafka-topics.sh --create --zookeeper 192.168.121.205:2181 --replication-factor 1 --partitions 1 --topic mykafka
//查看topic
bin/kafka-topics.sh --list --zookeeper 192.168.121.205:2181
//创建生产者
bin/kafka-console-producer.sh --broker-list 192.168.121.205:9092 --topic mykafka
//创建消费者
bin/kafka-console-consumer.sh --zookeeper 192.168.121.205:2181 --topic mykafka --from-beginning