Skip to content

Instantly share code, notes, and snippets.

@siwonpawel
Last active February 19, 2022 16:39
Show Gist options
  • Save siwonpawel/ccee1ed8a7734106c84e891182d583c8 to your computer and use it in GitHub Desktop.
Save siwonpawel/ccee1ed8a7734106c84e891182d583c8 to your computer and use it in GitHub Desktop.
Access Kafka inside Docker from host
# More information:
# https://www.confluent.io/blog/kafka-listeners-explained/
# https://docs.confluent.io/platform/current/app-development/kafkacat-usage.html
# Configuration #1
# Two Kafka listeners, one docker-internal (docker container - docker container) and one docker-external (host - docker container)
# from computer to kafka: localhost:9093
# from Docker internals: kafka:9092 (resolved by Docker DNS)
services:
zookeeper:
image: docker.io/bitnami/zookeeper:3.7
ports:
- "2181:2181"
volumes:
- "zookeeper_data:/bitnami"
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
kafka:
hostname: kafka
container_name: kafka
image: docker.io/bitnami/kafka:3
ports:
- "9093:9093"
volumes:
- "kafka_data:/bitnami"
depends_on:
- zookeeper
environment:
KAFKA_CFG_ZOOKEEPER_CONNECT: zookeeper:2181
ALLOW_PLAINTEXT_LISTENER: "yes"
KAFKA_LISTENERS: DOCKER_INTERNAL://kafka:9092,DOCKER_EXTERNAL://kafka:9093
KAFKA_ADVERTISED_LISTENERS: DOCKER_INTERNAL://kafka:9092,DOCKER_EXTERNAL://localhost:9093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: DOCKER_INTERNAL:PLAINTEXT,DOCKER_EXTERNAL:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER_INTERNAL
volumes:
zookeeper_data:
driver: local
kafka_data:
driver: local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment