Running bitnami/kafka in Docker
Even though there are many Docker images of various Kafka implementations, the documentation that accompanies each is not sufficient to get the container running and accessible from the host computers.
I hit this problem a while ago with the Confluent implementation, and now I am hitting it again with the Bitnami implementation.
If you go to (https://hub.docker.com/r/bitnami/kafka)[https://hub.docker.com/r/bitnami/kafka], it all sounds very simple, but you won’t be able to connect the Kafka server from your host machine.
I managed to get it working by copy pasting some of the command I used in the previous post. I’m sure that not every single line is needed, but I don’t have time to whittle it down.
Before running the container, you need to create a network -
docker network create kafka-bridge --driver bridge
And here is the command to run the container -
docker run --name kafka-server --hostname kafka-server \
--env KAFKA_BROKER_ID=1 \
--env KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT \
--env KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-server:51257,PLAINTEXT_HOST://localhost:64886 \
--env KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 \
--env KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=0 \
--env KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1 \
--env KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1 \
--env KAFKA_PROCESS_ROLES=broker,controller \
--env KAFKA_NODE_ID=1 \
--env KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka-server:51258 \
--env KAFKA_LISTENERS=PLAINTEXT://kafka-server:51257,CONTROLLER://kafka-server:51258,PLAINTEXT_HOST://0.0.0.0:64886 \
--env KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT \
--env KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER \
--env KAFKA_LOG_DIRS=/tmp/kraft-combined-logs \
--env KAFKA_REST_HOST_NAME=rest-proxy \
--env KAFKA_REST_LISTENERS=http://0.0.0.0:8082 \
--env KAFKA_REST_BOOTSTRAP_SERVERS=kafka-server:51257 \
--env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
--env container=oci \
--env LANG=C.UTF-8 \
--env UB_CLASSPATH=/usr/share/java/cp-base-lite/* --env=KAFKA_ZOOKEEPER_CONNECT= \
--env KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER \
--env CLUSTER_ID= \
--volume=/etc/kafka/secrets --volume=/var/lib/kafka/data \
--network=kafka-bridge \
-p 64886:64886 -p 8082:8082 \
bitnami/kafka:3.9.0
Then I can use my .NET applications to produce and consume from port 64886
.