Instructions for running apache/kafka:4.3.1 from Docker Hub:
https://hub.docker.com/layers/apache/kafka/4.3.1
docker pull apache/kafka:4.3.1
docker run --rm --name kafka -p 9092:9092 apache/kafka:4.3.1
This starts a single-node Kafka broker in KRaft mode.
The container’s default config listens on PLAINTEXT://localhost:9092, so from the host you can connect with localhost:9092.
docker exec -it kafka \
/opt/kafka/bin/kafka-console-producer.sh \
--topic test \
--bootstrap-server localhost:9092
Open a separate terminal and run the following:
docker exec -it kafka \
/opt/kafka/bin/kafka-console-consumer.sh \
--topic test \
--from-beginning \
--bootstrap-server localhost:9092
If you need to connect from other containers or hosts (not just localhost),
override the advertised listeners since the default is localhost-only:
docker run -d --name kafka -p 9092:9092 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://<your-host-ip-or-hostname>:9092,CONTROLLER://localhost:9093 \
apache/kafka:4.3.1
Exact env var names/defaults can shift slightly between versions — check the “How to use this image” section on the Docker Hub page for 4.3.1 specifics if the advertised-listener override doesn’t take effect.
Curious what a real, replicated cluster looks like? See the bonus Exercise 01b: Multi-Broker Kafka Cluster with Docker Compose (not part of the 2-day agenda).