Kafka access inside and outside docker

前端 未结 3 1084
遥遥无期
遥遥无期 2020-12-18 00:22

I\'m trying to start a kafka service using docker-compose, and it should be able to be accessed inside and outside docker. So, it should be matter of setting the right adver

3条回答
  •  温柔的废话
    2020-12-18 00:59

    What I needed to do was to declare the LISTENERS as both binding to the docker host, and then advertise them differently - one to the docker network, one to the host:

    services:
      zookeeper:
        image: confluentinc/cp-zookeeper
        ports:
          - "2181:2181"
        environment:
          ZOOKEEPER_CLIENT_PORT: 2181
          ZOOKEEPER_TICK_TIME: 2000
          ZOOKEEPER_SYNC_LIMIT: 2
      kafka:
        image: confluentinc/cp-kafka
        ports:
          - 9094:9094
        depends_on:
          - zookeeper
        environment:
          KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
          KAFKA_LISTENERS: INTERNAL://kafka:9092,OUTSIDE://kafka:9094
          KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:9092,OUTSIDE://localhost:9094
          KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,OUTSIDE:PLAINTEXT
          KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
    

提交回复
热议问题