Install Apache Kafka using Docker

Summary

One of my favourite messages/events streaming technology is Apache Kafka. Here is a very quick method to install Kafka in Linux using Docker.

Installation

Ensure that the following are installed:

docker --version
docker-compose --version

Create the docker-compose file:

touch docker-compose.yaml

File contents:

version: "3"
services:
  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    ports:
    - 2181:2181

  kafka:
    image: wurstmeister/kafka
    container_name: kafka
    ports:
    - 9092:9092
    environment:
      KAFKA_ADVERTISED_HOST_NAME: localhost
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

Start the service in the foreground:

docker-compose -f docker-compose.yml up

Or in the background:

docker-compose -f docker-compose.yml up -d