question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

exposing kafka from docker

See original GitHub issue

I’m using the Docker setup provided in this repo, and was wondering if anyone has tried to access the scraped data in the dockerized Kafka from outside of the container.

The docker-compose.yml file does expose the right ports, yet I couldn’t appear to subscribe to topics from outside the container, though from inside this worked well (using the same command).

This seemed like a Kafka + Docker problem, so I googled around, and most answers involved setting the KAFKA_ADVERTISED_HOST_NAME environment variable, currently absent from docker-compose.yml.

I tried setting that to different values (127.0.0.1 or localhost; kafka or scrapycluster_kafka_1 with an entry in my hosts file to route them to 127.0.0.1), but any of these would mess up the communication between the different containers for this repo – to the point where I also wasn’t able to verify whether the change had its intended effect.

At this point I’d wonder, has anyone else managed to interface with data scraped using the provided Docker Compose file from outside the container?

Steps to reproduce:

docker compose up
/opt/kafka/bin/kafka-topics.sh --zookeeper localhost:2181 --list
# ^ ok, works from both inside and from outside container
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --from-beginning --topic demo.incoming
curl 127.0.0.1:5343/feed -H "Content-Type: application/json" -d '{"url":"http
://www.google.com", "appid":"curl", "crawlid":"abc", "allowed_domains":["www.google.com"]}'
# ^ listen to topic and ensure it has messages -- successfully shows message from kafka container, not from host
^C
nano docker-compose.yml
# add environment variable for Kafka: KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
docker compose up
# bunch of errors:
# rest_1           | 2017-10-27 10:28:18,226 [rest-service] ERROR: Couldn't initialize kafka consumer for topic
# kafka_1          | waiting for kafka to be ready
...
# kafka_1          | [2017-10-27 10:28:25,891] WARN Unexpected error from /172.18.0.1; closing connection (org.apache.kafka.common.network.Selector)
# kafka_1          | org.apache.kafka.common.network.InvalidReceiveException: Invalid receive (size = 1195725856 larger than 104857600)
...
# rest_1           | 2017-10-27 10:28:58,742 [rest-service] ERROR: Failed to send message to Kafka

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

2reactions
gsunjkacommented, Nov 7, 2017

@tycho01

I had the same issue. After adding my host ip address to KAFKA_ADVERTISED_HOST_NAME everything worked fine.

0reactions
User1mcommented, Mar 22, 2019

thanks @gsunjka this helped solve my issue. in case you need to find the host ip address from dockers point run /sbin/ip route|awk '/default/ { print $3 }' inside a container

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to expose Kafka from Docker to the outside world?
You have to set the LISTENERS in environments in order to expose the Kafka brokers to external network like below :
Read more >
Guide to Setting Up Apache Kafka Using Docker - Baeldung
To start an Apache Kafka server, we'd first need to start a Zookeeper server. We can configure this dependency in a docker-compose.yml file, ......
Read more >
Get started with Kafka and Docker in 20 minutes - Architect.io
In this tutorial, we'll walk through how to use Docker, Kafka, ... The ports property instructs Zookeeper to expose itself to Kafka on...
Read more >
Kafka Primer for Docker: How to setup Kafka, start messaging ...
Kafka can be run as a docker service and exposed via listeners which allows clients to communicate with Kafka.
Read more >
Hello Kafka World! The complete guide to Kafka with Docker ...
Expose the Docker network and Kafka brokers​​ We basically added some environment to expose Kafka brokers to the host machine, if you want...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found