Skip to content

Instantly share code, notes, and snippets.

@aviflax
Last active January 7, 2022 22:33
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 aviflax/25c1196177722b6a93169df685618316 to your computer and use it in GitHub Desktop.
Save aviflax/25c1196177722b6a93169df685618316 to your computer and use it in GitHub Desktop.
A Docker setup for building and using a multi-architecture image with the Confluent Platform (community edition)
#!/bin/bash
## Configures and starts the Kafka broker
set -euo pipefail
(cat <<EOF
advertised.listeners=$KAFKA_ADVERTISED_LISTENERS
debug=true
zookeeper.connect=$KAFKA_ZOOKEEPER_CONNECT
EOF
) >> etc/kafka/server.properties
bin/kafka-server-start etc/kafka/server.properties
#!/bin/bash
## Configures and starts the Schema Registry
set -euo pipefail
(cat <<EOF
debug=true
host.name=$SCHEMA_REGISTRY_HOST_NAME
kafkastore.bootstrap.servers=$SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS
listeners=$SCHEMA_REGISTRY_LISTENERS
EOF
) > etc/schema-registry/schema-registry.properties
bin/schema-registry-start etc/schema-registry/schema-registry.properties
version: '2'
services:
zookeeper:
build: ./
command: bin/zookeeper-server-start etc/kafka/zookeeper.properties
ports:
- "2181:2181"
restart: unless-stopped
# TODO: the broker currently doesn’t handle restarts gracefully; it’s not able to reuse the
# Zookeeper session and it thus dies after restart, until 20 seconds has elapsed and ZK kills the
# prior session. This thread hints that there are some configs we could set that would address
# this: https://github.com/wurstmeister/kafka-docker/issues/389
broker:
build: ./
command: bin/broker
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
restart: unless-stopped
schema-registry:
build: ./
command: bin/schema-registry
depends_on:
- broker
ports:
- "8081:8081"
environment:
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: 'broker:9092'
SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8081
restart: unless-stopped
# We could use a smaller/simpler image to download the package, but this is the same base image as
# our ultimate image that we’re building, so we get to reuse the same cached layers.
FROM debian:buster-slim AS builder
WORKDIR /tmp/install
RUN apt-get update && apt-get install -yq wget
RUN wget --quiet \
-O confluent-community.tar.gz \
https://packages.confluent.io/archive/6.2/confluent-community-6.2.0.tar.gz
RUN tar -xzf confluent-community.tar.gz
# ----------------------
FROM adoptopenjdk/openjdk11:debianslim-jre
COPY --from=builder /tmp/install/confluent-6.2.0 /opt/confluent/platform
WORKDIR /opt/confluent/platform
COPY bin_broker bin/broker
COPY bin_schema-registry bin/schema-registry
RUN chmod +x bin/*
# We’re not setting a command because this image includes many programs.
# The caller will have to specify the command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment