Kafka install

From wikinotes

Docker Install

Single-node kafka setup for learning/experimenting.

kafka-ubuntu/kafka-start.sh

#!/usr/bin/env bash
#
# starts both zookeeper and kafka
#

bin/zookeeper-server-start.sh \
  config/zookeeper.properties \
  > zookeeper.log \
  & disown

# NOTE: add '& disown' yourself, otherwise ackward in docker-compose
bin/kafka-server-start.sh \
  config/server.properties \
  > kafka.log

kafka-ubuntu/Dockerfile

# vim: ft=Dockerfile
#
# DESCRIPTION:
#    quick single node kafka server to play with.
#
# INSTRUCTIONS:
#
#    use `docker-compose up`
#
#    docker build \
#      -t kafka-ubuntu:latest \
#      .
#


FROM ubuntu:18.04

ARG KAFKA_VERSION=2.5.0

RUN apt-get update && \
    apt-get install -yf sudo && \
    apt-get install -yf vim && \
    apt-get install -yf openjdk-8-jre && \
    apt-get install -yf curl && \
    echo .



# create user 'docker', add to sudoers list
RUN useradd -m docker && \
    echo "docker ALL = (ALL) NOPASSWD:ALL" >> /etc/sudoers

# start script
ADD kafka-start.sh /home/docker/kafka-start.sh
RUN chmod +x /home/docker/kafka-start.sh


# default to user 'docker' when logging in (instead of root)
USER docker

RUN curl https://apache.mirror.colo-serv.net/kafka/${KAFKA_VERSION}/kafka_2.12-${KAFKA_VERSION}.tgz \
    -o /home/docker/kafka-src.tgz

RUN test -d /home/docker/kafka \
      || mkdir /home/docker/kafka

RUN tar -xvf /home/docker/kafka-src.tgz \
      -C ~/kafka \
      --strip 1

RUN mv /home/docker/kafka-start.sh /home/docker/kafka/kafka-start.sh

# set pwd 
WORKDIR /home/docker/kafka

kafka-ubuntu/docker-compose.yml

#
version: '2'
services:
    kafka:
        build: 
            context: .
            dockerfile: Dockerfile
        image: kafka-ubuntu:latest
        command: ./kafka-start.sh
        ports:
            - "9092:9092"
docker-compose up              # build image, start server
docker-compose run kafka bash  # get shell in container
docker-compose down            # shutdown container