0
votes

I am trying to use kafka with the docker image Landoop/fast-data-dev I ran the following commands

I started the docker container

docker run --rm -it -p 2183:2181 -p 3030:3030 -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 9093:9092 -e ADV_HOST=127.0.0.1 landoop/fast-data-dev

then I started the bash command

docker run --rm -it --net=host landoop/fast-data-dev bash

then I created a topic

kafka-topics --create --zookeeper localhost:2183 --replication-factor 1 --partitions 3 --topic my-topic

then I tried to send data to the topic

kafka-console-producer --broker-list localhost:9093 --topic my-topic

but I was receiving the following error

[2018-10-27 20:08:24,655] WARN [Producer clientId=console-producer] Connection to node -1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

ps: because of "port already allocation" problem I changed the mappings of kafka and zookeeper to 9093 and 2183

1

1 Answers

0
votes

You're running the CLI commands within the container, so you can't just remap the port on the host. You'll actually need to also set the port within the container on which Kafka runs, using the BROKER_PORT variable, in this case.

docker run --rm -it -p 2183:2181 -p 3030:3030 -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 9093:9093 -e ADV_HOST=127.0.0.1 -e BROKER_PORT=9093 landoop/fast-data-dev

Otherwise, you still have to use localhost:9092 within the container even if the external port is 9093, but you never needed to add -p flags anyway to expose the ports externally if you were going to start bash within the container to do things.

If you wanted to use applications outside the container, see this blog, which uses Confluent containers, but same concept applies, though the landoop variables are different