我正在尝试为kafka主题设置docker映像。这就是我的docker-compose.yml文件中的内容
version: '2'
services:
kafka:
build:
context: .
dockerfile: etc/docker/sqlserver/kafka/Dockerfile
hostname: kafka-broker `
在Dockerfile旁边,我添加了以下几行以创建映像和创建该主题的命令。
FROM landoop/fast-data-dev:2.3.1
RUN docker exec -it kafka_broker kafka-topics --create --bootstrap-server localhost:9092 --
replication-factor 1 --partitions 1 --topic itemlocation
但是当我看到运行docker-compose ps时,没有创建容器。如果我做错了任何事情,请告诉我。我是docker和kafka的新手。
答案 0 :(得分:0)
您可以在“ wurstmeister / kafka”图像中使用“环境”创建主题:
version: '3'
services:
kafka:
image: wurstmeister/kafka
ports:
- "9092"
hostname: kafka-broker
environment:
KAFKA_CREATE_TOPICS: "itemlocation:1:1" # topic:partition:replicas
docker-compose.yml
version: '2'
services:
zookeeper:
image: zookeeper
container_name: zookeeper
kafka:
image: wurstmeister/kafka
container_name: kafka
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_CREATE_TOPICS: "itemlocation:1:1"
depends_on:
- zookeeper