Skip to content

Instantly share code, notes, and snippets.

@calvinlfer
Created May 7, 2022 20:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinlfer/1315f81532e889fd4e3990900cac8f04 to your computer and use it in GitHub Desktop.
Save calvinlfer/1315f81532e889fd4e3990900cac8f04 to your computer and use it in GitHub Desktop.
Single node Kafka docker-compose compatible with Docker on M1 Macs
version: "3.9"
services:
zookeeper:
restart: unless-stopped
image: ubuntu/zookeeper:latest
ports:
- "2181:2181"
kafka:
image: ubuntu/kafka:latest
entrypoint: /opt/kafka/bin/kafka-server-start.sh /etc/kafka/server.properties --override zookeeper.connect=zookeeper:2181 --override broker.id=1 --override advertised.listeners=PLAINTEXT://127.0.0.1:9092
ports:
- "9092:9092"
depends_on:
- zookeeper
@calvinlfer
Copy link
Author

Eliminate Zookeeper and use KRaft:

FROM ubuntu/kafka:latest

SHELL ["/bin/bash", "-c"]

# Set up KRaft directory
RUN export CLUSTER_ID=$(/opt/kafka/bin/kafka-storage.sh random-uuid) && \
    /opt/kafka/bin/kafka-storage.sh format --cluster-id $CLUSTER_ID --config /etc/kafka/kraft/server.properties

EXPOSE 9092
docker build . -t kraftykafka
version: "3.9"

services:
  kafka:
    image: kraftykafka
    command: /etc/kafka/kraft/server.properties --override advertised.listeners=PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 --override listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT --override listeners=PLAINTEXT://:29092,PLAINTEXT_HOST://:9092,CONTROLLER://:9093
    ports:
      - "9092:9092"

@calvinlfer
Copy link
Author

Single compose

version: "3.9"

services:
  kafka:
    image: ubuntu/kafka
    entrypoint: >
      bash -c "export CLUSTER_ID=$$(/opt/kafka/bin/kafka-storage.sh random-uuid) &&
      /opt/kafka/bin/kafka-storage.sh format --cluster-id $$CLUSTER_ID --config /etc/kafka/kraft/server.properties &&
      /opt/kafka/bin/kafka-server-start.sh /etc/kafka/kraft/server.properties 
        --override advertised.listeners=$$ADVERTISED_LISTENERS 
        --override listener.security.protocol.map=$$PROTOCOL_MAP
        --override listeners=$$LISTENERS"
    ports:
      - "9092:9092"
    environment:
      ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
      PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      LISTENERS: PLAINTEXT://:29092,PLAINTEXT_HOST://:9092,CONTROLLER://:9093

@calvinlfer
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment