1.拉取 Kafka 镜像
docker pull kafka:latest
2.创建 kafka 文件夹
mkdir kafka
3.进入 kafka 文件夹创建 docker-compose 文件
cd kafka
vim docker-compose.yml
4.添加内容
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: (服务器ip地址)
KAFKA_CREATE_TOPICS: "test:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
5.启动
docker-compose up -d