1

I am using docker to run a zookeeper and kafka instance with the following commands

docker run -it --rm --name zookeeper -p 2181:2181 -p 2888:2888 -p 3888:3888 debezium/zookeeper docker run -it --rm --name kafka -p 9092:9092 --link zookeeper:zookeeper -e ADVERTISED_HOST_NAME=localhost -e HOST_NAME=localhost debezium/kafka 

ADVERTISED_HOST_NAME is exposed outside container to localhost.

the kafka is connected to zookeeper and kafka output is as followed Using ZOOKEEPER_CONNECT=172.17.0.3:2181 Using KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 2020-07-26 03:56:23,160 - INFO [main:Log4jControllerRegistration$@31] - Registered kafka:type=kafka.Log4jController MBean 2020-07-26 03:56:26,313 - INFO [main:X509Util@79] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation 2020-07-26 03:56:26,554 - INFO [main:LoggingSignalHandler@72] - Registered signal handlers for TERM, INT, HUP 2020-07-26 03:56:26,580 - INFO [main:Logging@66] - starting 2020-07-26 03:56:26,593 - INFO [main:Logging@66] - Connecting to zookeeper on 172.17.0.3:2181 2020-07-26 03:56:26,700 - INFO [main:Logging@66] - [ZooKeeperClient Kafka server] Initializing a new session to 172.17.0.3:2181. 

the code to connect the kafka server is below

const { Kafka,logLevel,CompressionCodecs,CompressionTypes } = require('kafkajs'); const kafka1 = new Kafka({ clientId: 'my-app', brokers: ['localhost:9092'] }); 

but the kafka client could connect to kafka server with error "{"level":"ERROR","timestamp":"2020-07-26T02:53:30.472Z","logger":"kafkajs","message":"[BrokerPool] Failed to connect to seed broker, trying another broker from the list: Closed connection","retryCount":0,"retryTime":313}"

1 Answer 1

2

This behavior has to do with the --link flag. If you want to produce/consume data outside the docker network it will be required to add a lot of arguments to those docker run commands.

However, there is an easy(er) way to do it. Check out this docker-compose file! Replace the image names with the ones that you want ( e.g: confluentinc/cp-zookeeper:5.5.1 with debezium/zookeeper ), delete the services that you don't need and you're good to go!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.