docker pull wurstmeister/zookeeper
docker pull wurstmeister/kafka
docker run -d --name myzookeeper -p 2181:2181 -t wurstmeister/zookeeper
docker run -d --name kafka -p 9092:9092 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=172.17.0.2:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka
这样就启动了一个单个的Kafka容器, 通过docker客户端可以看到zookeeper容器和Kafka容器都是正常运行的
文件名: docker-compose.yml
文件内容:
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
expose:
- "2181"
kafka:
image: wurstmeister/kafka
depends_on:
- zookeeper
ports:
- "9092:9092"
expose:
- "9093"
environment:
KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:9093,OUTSIDE://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
KAFKA_LISTENERS: INSIDE://0.0.0.0:9093,OUTSIDE://0.0.0.0:9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
在上一步编写好的docker-compose.yml文件所在的文件路径下执行如下命令:
docker-compose build
正常结果如图所示:
构建成功后再执行如下命令:
docker-compose up -d
成功结果如图所示:
查看容器运行状态
说明zookeeper和Kafka服务都已成功运行.