嗨,我正在和docker建立kafka。我已经设法用已发布的合流图像设置zookeeper和kafka,请参见以下docker撰写文件:
version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:3.2.0
container_name: zookeeper
hostname: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
restart: always
kafka:
image: confluentinc/cp-kafka:3.2.0
hostname: kafka
container_name: kafka
depends_on:
- zookeeper
ports:
- '9092:9092'
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.99.100:9092
LISTENERS: PLAINTEXT://0.0.0.0:9092
restart: always
kafka-rest:
image: confluentinc/cp-kafka-rest:3.2.0
container_name: kafka-rest
depends_on:
- kafka
ports:
- '8082:8082'
environment:
KAFKA_REST_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_REST_LISTENERS: http://kafka-rest:8082
KAFKA_REST_SCHEMA_REGISTRY_URL: http://schema-registry:8081
KAFKA_REST_HOST_NAME: kafka-rest
restart: always
schema-registry:
image: confluentinc/cp-schema-registry:3.2.0
container_name: schema-registry
depends_on:
- kafka
ports:
- '8081'
environment:
SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: 'zookeeper:2181'
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_LISTENERS: http://schema-registry:8081
restart: always
connect:
image: confluentinc/cp-kafka-connect:3.2.0
container_name: kafka-connect
depends_on:
- zookeeper
- kafka
- schema-registry
ports:
- "8083:8083"
restart: always
environment:
CONNECT_BOOTSTRAP_SERVERS: 'kafka:9092'
CONNECT_REST_ADVERTISED_HOST_NAME: connect
CONNECT_REST_PORT: 8083
CONNECT_GROUP_ID: compose-connect-group
CONNECT_CONFIG_STORAGE_TOPIC: docker-connect-configs
CONNECT_OFFSET_STORAGE_TOPIC: docker-connect-offsets
CONNECT_STATUS_STORAGE_TOPIC: docker-connect-status
CONNECT_KEY_CONVERTER: io.confluent.connect.avro.AvroConverter
CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL: http://schema-registry:8081
CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter
CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: http://schema-registry:8081
CONNECT_INTERNAL_KEY_CONVERTER: org.apache.kafka.connect.json.JsonConverter
CONNECT_INTERNAL_VALUE_CONVERTER: org.apache.kafka.connect.json.JsonConverter
CONNECT_ZOOKEEPER_CONNECT: "zookeeper:2181"
现在,我已经成功地将kafka容器正确地公开给我的非dockinized应用程序,方法是将advised.listener属性正确地设置为plaintext://{docker\u machine\u ip}:9092,但是正如您所见,我还添加了其他合流应用程序来扩展我的kafka设置(kafka rest,schema registry)。由于advised.listener属性,这些无法再连接到我的kafka示例。
我可以将其更改为正确的容器主机名-->plaintext://kafka:9092但我失去了使用其他应用程序再次访问Kafka示例的能力。有什么简单的方法可以解决这个问题吗?
3条答案
按热度按时间qxsslcnc1#
假设这是一个针对本地开发环境的设置,下面是一个在docker网络中运行的解决方案。
此处更新-https://github.com/confluentinc/examples/blob/5.3.1-post/cp-all-in-one/docker-compose.yml
mdfafbf12#
奥马尔,也许你已经解决了你的问题,但是为了将来的参考,汉斯·杰斯珀森的评论对我起到了作用,即使是在windows上。
作为管理员,打开
C:\Windows\System32\drivers\etc\hosts
并添加以下行以将kafka代理公开为localhost。127.0.0.1 broker
还有我的docker-compose.yml
文件如下所示:或者,公开我的笔记本电脑的当前ip地址(使用ipconfig/all)也可以,但这样做的缺点是,每当我的网络发生变化时,我就必须更改
docker-compose.yml
文件也是。h22fl7wq3#
单Kafka和单缩放器