无法从docker(我的本地机器)外部连接汇流的docker kafka

时间:2018-06-03 11:38:44

标签: docker apache-kafka docker-compose confluent

我正在尝试定义一个docker-compose文件,它创建了汇合的kafka&动物园管理员。

似乎我无法从docker外部连接到kafka(同时,在docker-compose文件中定义的网络中使用kafka,由其他容器/服务使用)

我试图设置“KAFKA_ADVERTISED_LISTENERS”,其值为“PLAINTEXT://:9092但没有运气。”

version: '3'

services:   zookeeper:
    image: confluentinc/cp-zookeeper:4.1.1
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    ports:
      - "2181:2181"
      - "2888:2888"
      - "3888:3888"
    extra_hosts:
      - "moby:127.0.0.1"
      - "localhost: 127.0.0.1"

  kafka:
    image: confluentinc/cp-kafka:4.1.1
    depends_on:
      - zookeeper
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
    ports:
      - "9092:9092"
    extra_hosts:
      - "moby:127.0.0.1"
      - "localhost: 127.0.0.1"


  kafka-topics-init:
    image: confluentinc/cp-kafka:4.1.1
    container_name: kafka-topics-init
    depends_on:
      - kafka
    command: "bash -c -a 'echo Waiting for Kafka to be ready... && \
                       /etc/confluent/docker/configure && \
                       cub kafka-ready -b kafka:9092 1 60 --config /etc/kafka/kafka.properties && \
                       sleep 5 && \
                       kafka-topics --zookeeper zookeeper:2181 --topic sometopic --create --replication-factor 1 --partitions 1'"
    environment:
      # The following settings are listed here only to satisfy the image's requirements.
      # We override the image's `command` anyways, hence this container will not start a broker.
      KAFKA_BROKER_ID: ignored
      KAFKA_ZOOKEEPER_CONNECT: ignored
      KAFKA_ADVERTISED_LISTENERS: ignored


# MORE CONTAINERS WHICH USES KAFKA

0 个答案:

没有答案