I'm trying to connect to kafka docker container from another docker container. But it didn't connect.
There are the list of containers using for kafka messaging
Network kafka-docker_default has two containers kafka-docker_zookeeper_1 and kafka-docker_kafka0_1
For running kafka and zookeeper I used docker-compose file:
version: '2'
services:
zookeeper:
image: "confluentinc/cp-zookeeper:latest"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
# This has three listeners you can experiment with.
# BOB for internal traffic on the Docker network
# FRED for traffic from the Docker-host machine (`localhost`)
# ALICE for traffic from outside, reaching the Docker host on the DNS name `never-gonna-give-you-up`
# Use
kafka0:
image: "confluentinc/cp-kafka"
ports:
- '9092:9092'
- '29094:29094'
depends_on:
- zookeeper
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENERS: LISTENER_BOB://kafka0:29092,LISTENER_FRED://kafka0:9092,LISTENER_ALICE://kafka0:29094
KAFKA_ADVERTISED_LISTENERS: LISTENER_BOB://kafka0:29092,LISTENER_FRED://localhost:9092,LISTENER_ALICE://never-gonna-give-you-up:29094
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_BOB:PLAINTEXT,LISTENER_FRED:PLAINTEXT,LISTENER_ALICE:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_BOB
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
Containers dockercompose17138956372294708100_kafkatest.producer_1 and dockercompose17138956372294708100_kafkatest.consumer_1 are for produce and consume messages. While container dockercompose17138956372294708100_kafkatest.producer_1 is trying to connect to kafka cluster using bootstrap.servers parameter(localhost:9092 or never-gonna-give-you-up:29094) it showed error
%7|1569945335.015|BROKERFAIL|rdkafka#producer-1| [thrd:never-gonna-give-you-up:29094/bootstrap]: never-gonna-give-you-up:29094/bootstrap: failed: err: Local: Host resolution failure: (errno: Bad address)
%3|1569945335.015|FAIL|rdkafka#producer-1| [thrd:never-gonna-give-you-up:29094/bootstrap]: never-gonna-give-you-up:29094/bootstrap: Failed to resolve 'never-gonna-give-you-up:29094': Name or service not known (after 1656ms in state CONNECT)
%3|1569945335.015|ERROR|rdkafka#producer-1| [thrd:never-gonna-give-you-up:29094/bootstrap]: never-gonna-give-you-up:29094/bootstrap: Failed to resolve 'never-gonna-give-you-up:29094': Name or service not known (after 1656ms in state CONNECT)
%7|1569945335.015|STATE|rdkafka#producer-1| [thrd:never-gonna-give-you-up:29094/bootstrap]: never-gonna-give-you-up:29094/bootstrap: Broker changed state CONNECT -> DOWN
%3|1569945335.015|ERROR|rdkafka#producer-1| [thrd:never-gonna-give-you-up:29094/bootstrap]: 1/1 brokers are down
How can I fix it?