我正在尝试在docker容器中设置Kafka以进行本地开发。我的docker-compose.yml如下所示:
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181"
hostname: zookeeper
kafka:
image: wurstmeister/kafka
command: [start-kafka.sh]
ports:
- "9092"
hostname: kafka
environment:
KAFKA_CREATE_TOPICS: "UploadFile:1:1,GetFile:1:1,TrackUpload:1:1,GetEmailContent:1:1" # topic:partition:replicas
KAFKA_ADVERTISED_HOST_NAME: kafka # docker-machine ip
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_PORT: 9092
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- "zookeeper"
不幸的是,我在本地主机(不在docker中)运行的节点应用无法连接到它。我使用了网址“ kafka:9092”,甚至是“ localhost:9092”。什么都没有。知道发生了什么事吗?
答案 0 :(得分:2)
暴露用于kafka服务的主机端口9092,您应该能够从应用程序或主机通过“ localhost:9092”进行连接。
....
kafka:
image: wurstmeister/kafka
command: [start-kafka.sh]
ports:
- "9092:9092"
....