Skip to main content

Access kafka on docker from host machine

Access kafka on docker from host machine

Problem

You can easily create kafka container using docker.
We are using docker compose to create kafka, storm container.
This setup is working fine but we cannot send any message from host machine to kafka running on docker container.
All ports are currently mapped to host machine.
I can ssh to docker container and send message but i was not able to send any message from my host.
It is very irritating as i cannot use application running in Intellij to send any message to kafka on docker.

Solution

When i use docker compose to create docker container i use following configuration
kafka:    
    image: docker image
    ports: - "2181:2181"    
           - "9092:9092"  
           - "9000:9000"
 environment:  
 KAFKA_CREATE_TOPICS: topic1
 ADVERTISED_HOST: kafka
Notice that we set ADVERTISER_HOST as kafka.
Now open your host file and put following entries(this depends on environment linux/windows/mac).
<<ip address of docker machine>> kafka

Now in your program use kafka as zookeeper host instead of ip address.


Comments

Popular posts from this blog

How to auto scale Kinesis stream

We have used AWS Kinesis stream in nodejs project. It is very easy to get started with Kinesis. You can setup Kinesis to handle any amount of traffic. For every queue you  create stream in Kinesis. Each stream has many shards. One shard can handle 1000 req/sec. To handle more traffic you can create many shards. Every shard cost money and unused shards are waste of money. Only problem with Kinesis is that there are not automatic way where AWS itself create and destroy shards as per current traffic. To handle this scenario we have created one nodejs module which continuously monitor traffic and create/destroy shards. I have proposed that since this is very common requirement we can contribute this code to open source. We have used many open source framework and this is one of the way to give something back to community. With permission from client i have created nodejs module and publish it on github and npm. You can find source code at https://github.com/xaxis-open-sou...