Kafka on Docker and Spring Producer Application Kafka on Docker and Spring Producer Application docker docker

Kafka on Docker and Spring Producer Application


Using bitnami stack

version: '3'services:  zookeeper:    container_name: zookeeper    image: 'bitnami/zookeeper:3.4.14'    ports:      - '2181:2181'    volumes:      - 'zookeeper_data:/bitnami'    environment:      - ALLOW_ANONYMOUS_LOGIN=yes    restart: unless-stopped  kafka:    container_name: kafka    image: 'bitnami/kafka:2.3.0'    ports:      - '9092:9092'    volumes:      - 'kafka_data:/bitnami'    environment:      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181      - ALLOW_PLAINTEXT_LISTENER=yes      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092    depends_on:      - zookeeper    restart: unless-stoppedvolumes:  zookeeper_data:    driver: local  kafka_data:    driver: local

Check their guide - there are a lot of insights on how it works + Kafka cluster + more

https://hub.docker.com/r/bitnami/kafka


I think your listener's address is not configured well. It should be localhost or the actual docker host name.

This is a working example from my project. Note that I use the original confluence image, but it should work with wurstmeister's image too:

version: '3.7'services:  zookeeper:    image: confluentinc/cp-zookeeper    hostname: zookeeper    environment:      ZOOKEEPER_SERVER_ID: 1      ZOOKEEPER_CLIENT_PORT: "2181"      ZOOKEEPER_TICK_TIME: "2000"      ZOOKEEPER_SERVERS: "zookeeper:22888:23888"    ports:      - 2181:2181  kafka:    image: confluentinc/cp-kafka    hostname: kafka    depends_on:      - zookeeper    environment:      KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT,PLAINTEXT_UI:PLAINTEXT      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT      KAFKA_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://kafka:9092      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092      KAFKA_BROKER_ID: 1      KAFKA_BROKER_RACK: "r1"      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1      KAFKA_DELETE_TOPIC_ENABLE: "true"      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"    ports:      - 9092:9092      - 29092:29092


My docker-compose file:

version: "3"services:  zookeeper:    container_name: zookeeper    image: confluentinc/cp-zookeeper:5.3.1    ports:      - "2181:2181"    environment:      ZOOKEEPER_CLIENT_PORT: 2181      ZOOKEEPER_TICK_TIME: 2000    volumes:      - zookeeper-data:/var/lib/zookeeper/data      - zookeeper-log:/var/lib/zookeeper/log  kafka:    container_name: kafka    image: confluentinc/cp-kafka:5.3.1    depends_on:      - zookeeper    ports:      - "9092:9092"      - "29092:29092"    environment:      KAFKA_BROKER_ID: 1      KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://${DOCKER_HOST_IP:-127.0.0.1}:9092      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1    volumes:      - kafka-data:/var/lib/kafka/datavolumes:  zookeeper-data:  zookeeper-log:  kafka-data: